diff --git a/djed-sdk/dist/esm/index.js b/djed-sdk/dist/esm/index.js index f030428..e0d75d2 100644 --- a/djed-sdk/dist/esm/index.js +++ b/djed-sdk/dist/esm/index.js @@ -253,10 +253,11 @@ const calculateIsRatioAboveMin = ({ * @param {*} amountUSD * @param {*} totalSCSupply * @param {*} thresholdSCSupply + * @param {*} txLimit * @returns */ -const isTxLimitReached = (amountUSD, totalSCSupply, thresholdSCSupply) => - amountUSD > TRANSACTION_USD_LIMIT && +const isTxLimitReached = (amountUSD, totalSCSupply, thresholdSCSupply, txLimit) => + (BigInt(amountUSD) > BigInt(txLimit || TRANSACTION_USD_LIMIT)) && BigInt(totalSCSupply) >= BigInt(thresholdSCSupply); const promiseTx = (isWalletConnected, tx, signer) => { @@ -344,6 +345,26 @@ const getFees = async (djed) => { } }; +/** + * Function that returns the correct price method name based on the contract version and operation + * @param {*} djed Djed contract + * @param {*} operation 'buySC', 'sellSC', 'buyRC', 'sellRC' + * @returns + */ +const getPriceMethod = async (djed, operation) => { + const isShu = await djed.methods.scMaxPrice(0).call().then(() => true).catch(() => false); + + if (!isShu) return "scPrice"; + + switch (operation) { + case 'buySC': return "scMaxPrice"; + case 'sellSC': return "scMinPrice"; + case 'buyRC': return "scMinPrice"; + case 'sellRC': return "scMaxPrice"; + default: return "scPrice"; + } +}; + /** * Function that calculates fees and how much BC (totalBCAmount) user should pay to receive desired amount of reserve coin * @param {*} djed DjedContract @@ -353,6 +374,7 @@ const getFees = async (djed) => { */ const tradeDataPriceBuyRc = async (djed, rcDecimals, amountScaled) => { try { + const scMethod = await getPriceMethod(djed, 'buyRC'); const data = await tradeDataPriceCore( djed, "rcBuyingPrice", @@ -379,6 +401,7 @@ const tradeDataPriceBuyRc = async (djed, rcDecimals, amountScaled) => { const tradeDataPriceSellRc = async (djed, rcDecimals, amountScaled) => { try { + const scMethod = await getPriceMethod(djed, 'sellRC'); const data = await tradeDataPriceCore( djed, "rcTargetPrice", @@ -428,9 +451,10 @@ const sellRcTx = (djed, account, amount, UI, DJED_ADDRESS) => { */ const tradeDataPriceBuySc = async (djed, scDecimals, amountScaled) => { try { + const method = await getPriceMethod(djed, 'buySC'); const data = await tradeDataPriceCore( djed, - "scPrice", + method, scDecimals, amountScaled ); @@ -461,9 +485,10 @@ const tradeDataPriceBuySc = async (djed, scDecimals, amountScaled) => { */ const tradeDataPriceSellSc = async (djed, scDecimals, amountScaled) => { try { + const method = await getPriceMethod(djed, 'sellSC'); const data = await tradeDataPriceCore( djed, - "scPrice", + method, scDecimals, amountScaled ); @@ -543,8 +568,169 @@ const calculateFutureScPrice = async ({ } }; -var contractName$2 = "Djed"; -var abi$2 = [ +/** + * Function that calculates fees and how much BC (totalBCAmount) user will receive if he sells desired amount of stable coin and reserve coin + * @param {*} djed DjedContract + * @param {*} scDecimals Stable coin decimals + * @param {*} rcDecimals Reserve coin decimals + * @param {*} amountScScaled Stable coin amount that user wants to sell + * @param {*} amountRcScaled Reserve coin amount that user wants to sell + * @returns + */ +const tradeDataPriceSellBoth = async ( + djed, + scDecimals, + rcDecimals, + amountScScaled, + amountRcScaled +) => { + try { + const scPriceMethod = await getPriceMethod(djed, 'sellSC'); + const [scPriceData, rcPriceData] = await Promise.all([ + scaledUnscaledPromise(web3Promise$1(djed, scPriceMethod, 0), BC_DECIMALS), + scaledUnscaledPromise(web3Promise$1(djed, "rcTargetPrice", 0), BC_DECIMALS), + ]); + + const amountScUnscaled = decimalUnscaling(amountScScaled, scDecimals); + const amountRcUnscaled = decimalUnscaling(amountRcScaled, rcDecimals); + + const scValueBC = convertToBC( + amountScUnscaled, + scPriceData[1], + scDecimals + ); + const rcValueBC = convertToBC( + amountRcUnscaled, + rcPriceData[1], + rcDecimals + ); + + const totalValueBC = (scValueBC + rcValueBC).toString(); + + const { treasuryFee, fee } = await getFees(djed); + const totalBCAmount = deductFees(totalValueBC, fee, treasuryFee); + + return { + scPriceScaled: scPriceData[0], + scPriceUnscaled: scPriceData[1], + rcPriceScaled: rcPriceData[0], + rcPriceUnscaled: rcPriceData[1], + amountScUnscaled, + amountRcUnscaled, + totalBCScaled: decimalScaling(totalBCAmount.toString(), BC_DECIMALS), + totalBCUnscaled: totalBCAmount.toString(), + }; + } catch (error) { + console.error("Error in tradeDataPriceSellBoth:", error); + } +}; + +/** + * Function to sell both stablecoins and reservecoins + * @param {*} djed DjedContract + * @param {*} account User address + * @param {*} amountSC Unscaled amount of stablecoins to sell + * @param {*} amountRC Unscaled amount of reservecoins to sell + * @param {*} UI UI address for fee + * @param {*} DJED_ADDRESS Address of Djed contract + * @returns + */ +const sellBothTx = ( + djed, + account, + amountSC, + amountRC, + UI, + DJED_ADDRESS +) => { + const data = djed.methods + .sellBothCoins(amountSC, amountRC, account, FEE_UI_UNSCALED, UI) + .encodeABI(); + return buildTx(account, DJED_ADDRESS, 0, data); +}; + +// # ISIS / TEFNUT Transaction Functions (ERC20 Base Asset) + +/** + * Buy StableCoins (Isis/Tefnut Variant - ERC20 Base Asset) + * Note: Caller must APPROVE the Djed contract to spend `amountBC` of the Base Asset before calling this. + * @param {object} djed The DjedContract instance + * @param {string} payer The address paying the Base Asset + * @param {string} receiver The address receiving the StableCoins + * @param {string} amountBC The amount of Base Asset to pay (in wei/smallest unit) + * @param {string} UI The UI address + * @param {string} DJED_ADDRESS The Djed contract address + * @returns {object} The transaction object + */ +const buyScIsisTx = (djed, payer, receiver, amountBC, UI, DJED_ADDRESS) => { + // Signature: buyStableCoins(uint256 amountBC, address receiver, uint256 feeUI, address ui) + const data = djed.methods + .buyStableCoins(amountBC, receiver, FEE_UI_UNSCALED, UI) + .encodeABI(); + + // Value is 0 because Base Asset is ERC20 transferFrom, not msg.value + return buildTx(payer, DJED_ADDRESS, 0, data); +}; + +/** + * Sell StableCoins (Isis/Tefnut Variant) + * Note: Same logic as Osiris, but ensuring naming consistency if needed. + * But functionally, sellStableCoins signature is: sellStableCoins(uint256 amountSC, address receiver, uint256 feeUI, address ui) + * which matches Osiris. Using the same function is fine, but we provide an alias for clarity. + */ +const sellScIsisTx = (djed, account, amountSC, UI, DJED_ADDRESS) => { + // Signature: sellStableCoins(uint256 amountSC, address receiver, uint256 feeUI, address ui) + // This is identical to Osiris, so we can reuse the logic or just wrap it. + // However, the internal implementation of Djed Isis would transfer ERC20 back to user. + const data = djed.methods + .sellStableCoins(amountSC, account, FEE_UI_UNSCALED, UI) + .encodeABI(); + return buildTx(account, DJED_ADDRESS, 0, data); +}; + +/** + * Buy ReserveCoins (Isis/Tefnut Variant - ERC20 Base Asset) + * Note: Caller must APPROVE the Djed contract to spend `amountBC` of the Base Asset before calling this. + * @param {object} djed The DjedContract instance + * @param {string} payer The address paying the Base Asset + * @param {string} receiver The address receiving the ReserveCoins + * @param {string} amountBC The amount of Base Asset to pay (in wei/smallest unit) + * @param {string} UI The UI address + * @param {string} DJED_ADDRESS The Djed contract address + * @returns {object} The transaction object + */ +const buyRcIsisTx = (djed, payer, receiver, amountBC, UI, DJED_ADDRESS) => { + // Signature: buyReserveCoins(uint256 amountBC, address receiver, uint256 feeUI, address ui) + const data = djed.methods + .buyReserveCoins(amountBC, receiver, FEE_UI_UNSCALED, UI) + .encodeABI(); + + return buildTx(payer, DJED_ADDRESS, 0, data); + }; + +const sellRcIsisTx = (djed, account, amountRC, UI, DJED_ADDRESS) => { + // Signature: sellReserveCoins(uint256 amountRC, address receiver, uint256 feeUI, address ui) + const data = djed.methods + .sellReserveCoins(amountRC, account, FEE_UI_UNSCALED, UI) + .encodeABI(); + return buildTx(account, DJED_ADDRESS, 0, data); +}; + +/** + * Sell Both Coins (Isis/Tefnut Variant) + * Note: Same logic as Osiris. + */ +const sellBothIsisTx = (djed, account, amountSC, amountRC, UI, DJED_ADDRESS) => { + // Signature: sellBothCoins(uint256 amountSC, uint256 amountRC, address receiver, uint256 feeUI, address ui) + // Actually, check Djed.sol: sellBothCoins(uint256 amountSC, uint256 amountRC, address receiver, uint256 feeUI, address ui) + const data = djed.methods + .sellBothCoins(amountSC, amountRC, account, FEE_UI_UNSCALED, UI) + .encodeABI(); + return buildTx(account, DJED_ADDRESS, 0, data); +}; + +var contractName$4 = "Djed"; +var abi$7 = [ { inputs: [ { @@ -1267,95 +1453,35 @@ var abi$2 = [ ], stateMutability: "view", type: "function" - } -]; -var djedArtifact = { - contractName: contractName$2, - abi: abi$2 -}; - -var contractName$1 = "Coin"; -var abi$1 = [ - { - inputs: [ - { - internalType: "string", - name: "name", - type: "string" - }, - { - internalType: "string", - name: "symbol", - type: "string" - } - ], - stateMutability: "nonpayable", - type: "constructor" }, { - anonymous: false, inputs: [ { - indexed: true, - internalType: "address", - name: "owner", - type: "address" - }, - { - indexed: true, - internalType: "address", - name: "spender", - type: "address" - }, - { - indexed: false, internalType: "uint256", - name: "value", + name: "_currentPaymentAmount", type: "uint256" } ], - name: "Approval", - type: "event" - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "address", - name: "from", - type: "address" - }, - { - indexed: true, - internalType: "address", - name: "to", - type: "address" - }, + name: "scMaxPrice", + outputs: [ { - indexed: false, internalType: "uint256", - name: "value", + name: "", type: "uint256" } ], - name: "Transfer", - type: "event" + stateMutability: "view", + type: "function" }, { inputs: [ { - internalType: "address", - name: "owner", - type: "address" - }, - { - internalType: "address", - name: "spender", - type: "address" + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" } ], - name: "allowance", + name: "scMinPrice", outputs: [ { internalType: "uint256", @@ -1368,37 +1494,22 @@ var abi$1 = [ }, { inputs: [ - { - internalType: "address", - name: "spender", - type: "address" - }, - { - internalType: "uint256", - name: "amount", - type: "uint256" - } ], - name: "approve", + name: "ratioMax", outputs: [ { - internalType: "bool", + internalType: "uint256", name: "", - type: "bool" + type: "uint256" } ], - stateMutability: "nonpayable", + stateMutability: "view", type: "function" }, { inputs: [ - { - internalType: "address", - name: "account", - type: "address" - } ], - name: "balanceOf", + name: "ratioMin", outputs: [ { internalType: "uint256", @@ -1411,55 +1522,1837 @@ var abi$1 = [ }, { inputs: [ - { - internalType: "address", - name: "spender", - type: "address" - }, - { - internalType: "uint256", - name: "subtractedValue", - type: "uint256" - } ], - name: "decreaseAllowance", + name: "updateOracleValues", outputs: [ - { - internalType: "bool", - name: "", - type: "bool" - } ], stateMutability: "nonpayable", type: "function" - }, + } +]; +var djedArtifact = { + contractName: contractName$4, + abi: abi$7 +}; + +var contractName$3 = "Djed"; +var abi$6 = [ { inputs: [ { internalType: "address", - name: "spender", + name: "oracleAddress", type: "address" }, { internalType: "uint256", - name: "addedValue", + name: "_scalingFactor", type: "uint256" - } - ], - name: "increaseAllowance", - outputs: [ + }, { - internalType: "bool", - name: "", - type: "bool" + internalType: "address", + name: "_treasury", + type: "address" + }, + { + internalType: "uint256", + name: "_initialTreasuryFee", + type: "uint256" + }, + { + internalType: "uint256", + name: "_treasuryRevenueTarget", + type: "uint256" + }, + { + internalType: "uint256", + name: "_reserveRatioMin", + type: "uint256" + }, + { + internalType: "uint256", + name: "_reserveRatioMax", + type: "uint256" + }, + { + internalType: "uint256", + name: "_fee", + type: "uint256" + }, + { + internalType: "uint256", + name: "_thresholdSupplySC", + type: "uint256" + }, + { + internalType: "uint256", + name: "_rcMinPrice", + type: "uint256" + }, + { + internalType: "uint256", + name: "_txLimit", + type: "uint256" } ], - stateMutability: "nonpayable", - type: "function" + stateMutability: "payable", + type: "constructor" }, { + anonymous: false, inputs: [ - ], + { + indexed: true, + internalType: "address", + name: "buyer", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "receiver", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "amountRC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountBC", + type: "uint256" + } + ], + name: "BoughtReserveCoins", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "buyer", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "receiver", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "amountSC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountBC", + type: "uint256" + } + ], + name: "BoughtStableCoins", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "seller", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "receiver", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "amountSC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountRC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountBC", + type: "uint256" + } + ], + name: "SoldBothCoins", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "seller", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "receiver", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "amountRC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountBC", + type: "uint256" + } + ], + name: "SoldReserveCoins", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "seller", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "receiver", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "amountSC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountBC", + type: "uint256" + } + ], + name: "SoldStableCoins", + type: "event" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "E", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "L", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "R", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "amount", + type: "uint256" + }, + { + internalType: "address", + name: "receiver", + type: "address" + }, + { + internalType: "uint256", + name: "fee_ui", + type: "uint256" + }, + { + internalType: "address", + name: "ui", + type: "address" + } + ], + name: "buyReserveCoins", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "amount", + type: "uint256" + }, + { + internalType: "address", + name: "receiver", + type: "address" + }, + { + internalType: "uint256", + name: "feeUI", + type: "uint256" + }, + { + internalType: "address", + name: "ui", + type: "address" + } + ], + name: "buyStableCoins", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + ], + name: "fee", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "initialTreasuryFee", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "oracle", + outputs: [ + { + internalType: "contract IFreeOracle", + name: "", + type: "address" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "ratio", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "rcBuyingPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "rcDecimalScalingFactor", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "rcMinPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "rcTargetPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "reserveCoin", + outputs: [ + { + internalType: "contract Coin", + name: "", + type: "address" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "reserveRatioMax", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "reserveRatioMin", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "scDecimalScalingFactor", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "scPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "scalingFactor", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "amountSC", + type: "uint256" + }, + { + internalType: "uint256", + name: "amountRC", + type: "uint256" + }, + { + internalType: "address", + name: "receiver", + type: "address" + }, + { + internalType: "uint256", + name: "fee_ui", + type: "uint256" + }, + { + internalType: "address", + name: "ui", + type: "address" + } + ], + name: "sellBothCoins", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "amountRC", + type: "uint256" + }, + { + internalType: "address", + name: "receiver", + type: "address" + }, + { + internalType: "uint256", + name: "fee_ui", + type: "uint256" + }, + { + internalType: "address", + name: "ui", + type: "address" + } + ], + name: "sellReserveCoins", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "amountSC", + type: "uint256" + }, + { + internalType: "address", + name: "receiver", + type: "address" + }, + { + internalType: "uint256", + name: "feeUI", + type: "uint256" + }, + { + internalType: "address", + name: "ui", + type: "address" + } + ], + name: "sellStableCoins", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + ], + name: "stableCoin", + outputs: [ + { + internalType: "contract Coin", + name: "", + type: "address" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "thresholdSupplySC", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "treasury", + outputs: [ + { + internalType: "address", + name: "", + type: "address" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "treasuryFee", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "treasuryRevenue", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "treasuryRevenueTarget", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "txLimit", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "scMaxPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "scMinPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "ratioMax", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "ratioMin", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "updateOracleValues", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + } +]; +var djedIsisArtifact = { + contractName: contractName$3, + abi: abi$6 +}; + +var contractName$2 = "Djed"; +var abi$5 = [ + { + inputs: [ + { + internalType: "address", + name: "oracleAddress", + type: "address" + }, + { + internalType: "uint256", + name: "_scalingFactor", + type: "uint256" + }, + { + internalType: "address", + name: "_treasury", + type: "address" + }, + { + internalType: "uint256", + name: "_initialTreasuryFee", + type: "uint256" + }, + { + internalType: "uint256", + name: "_treasuryRevenueTarget", + type: "uint256" + }, + { + internalType: "uint256", + name: "_reserveRatioMin", + type: "uint256" + }, + { + internalType: "uint256", + name: "_reserveRatioMax", + type: "uint256" + }, + { + internalType: "uint256", + name: "_fee", + type: "uint256" + }, + { + internalType: "uint256", + name: "_thresholdSupplySC", + type: "uint256" + }, + { + internalType: "uint256", + name: "_rcMinPrice", + type: "uint256" + }, + { + internalType: "uint256", + name: "_txLimit", + type: "uint256" + } + ], + stateMutability: "payable", + type: "constructor" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "buyer", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "receiver", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "amountRC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountBC", + type: "uint256" + } + ], + name: "BoughtReserveCoins", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "buyer", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "receiver", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "amountSC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountBC", + type: "uint256" + } + ], + name: "BoughtStableCoins", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "seller", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "receiver", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "amountSC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountRC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountBC", + type: "uint256" + } + ], + name: "SoldBothCoins", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "seller", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "receiver", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "amountRC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountBC", + type: "uint256" + } + ], + name: "SoldReserveCoins", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "seller", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "receiver", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "amountSC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountBC", + type: "uint256" + } + ], + name: "SoldStableCoins", + type: "event" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "E", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "L", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "R", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "amount", + type: "uint256" + }, + { + internalType: "address", + name: "receiver", + type: "address" + }, + { + internalType: "uint256", + name: "fee_ui", + type: "uint256" + }, + { + internalType: "address", + name: "ui", + type: "address" + } + ], + name: "buyReserveCoins", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "amount", + type: "uint256" + }, + { + internalType: "address", + name: "receiver", + type: "address" + }, + { + internalType: "uint256", + name: "feeUI", + type: "uint256" + }, + { + internalType: "address", + name: "ui", + type: "address" + } + ], + name: "buyStableCoins", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + ], + name: "fee", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "initialTreasuryFee", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "oracle", + outputs: [ + { + internalType: "contract IFreeOracle", + name: "", + type: "address" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "ratio", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "rcBuyingPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "rcDecimalScalingFactor", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "rcMinPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "rcTargetPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "reserveCoin", + outputs: [ + { + internalType: "contract Coin", + name: "", + type: "address" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "reserveRatioMax", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "reserveRatioMin", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "scDecimalScalingFactor", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "scPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "scalingFactor", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "amountSC", + type: "uint256" + }, + { + internalType: "uint256", + name: "amountRC", + type: "uint256" + }, + { + internalType: "address", + name: "receiver", + type: "address" + }, + { + internalType: "uint256", + name: "fee_ui", + type: "uint256" + }, + { + internalType: "address", + name: "ui", + type: "address" + } + ], + name: "sellBothCoins", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "amountRC", + type: "uint256" + }, + { + internalType: "address", + name: "receiver", + type: "address" + }, + { + internalType: "uint256", + name: "fee_ui", + type: "uint256" + }, + { + internalType: "address", + name: "ui", + type: "address" + } + ], + name: "sellReserveCoins", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "amountSC", + type: "uint256" + }, + { + internalType: "address", + name: "receiver", + type: "address" + }, + { + internalType: "uint256", + name: "feeUI", + type: "uint256" + }, + { + internalType: "address", + name: "ui", + type: "address" + } + ], + name: "sellStableCoins", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + ], + name: "stableCoin", + outputs: [ + { + internalType: "contract Coin", + name: "", + type: "address" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "thresholdSupplySC", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "treasury", + outputs: [ + { + internalType: "address", + name: "", + type: "address" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "treasuryFee", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "treasuryRevenue", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "treasuryRevenueTarget", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "txLimit", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "scMaxPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "scMinPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "ratioMax", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "ratioMin", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "updateOracleValues", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + } +]; +var djedTefnutArtifact = { + contractName: contractName$2, + abi: abi$5 +}; + +var contractName$1 = "Coin"; +var abi$4 = [ + { + inputs: [ + { + internalType: "string", + name: "name", + type: "string" + }, + { + internalType: "string", + name: "symbol", + type: "string" + } + ], + stateMutability: "nonpayable", + type: "constructor" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "owner", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "spender", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "value", + type: "uint256" + } + ], + name: "Approval", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "from", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "to", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "value", + type: "uint256" + } + ], + name: "Transfer", + type: "event" + }, + { + inputs: [ + { + internalType: "address", + name: "owner", + type: "address" + }, + { + internalType: "address", + name: "spender", + type: "address" + } + ], + name: "allowance", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "spender", + type: "address" + }, + { + internalType: "uint256", + name: "amount", + type: "uint256" + } + ], + name: "approve", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool" + } + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "account", + type: "address" + } + ], + name: "balanceOf", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "spender", + type: "address" + }, + { + internalType: "uint256", + name: "subtractedValue", + type: "uint256" + } + ], + name: "decreaseAllowance", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool" + } + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "spender", + type: "address" + }, + { + internalType: "uint256", + name: "addedValue", + type: "uint256" + } + ], + name: "increaseAllowance", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool" + } + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + ], name: "name", outputs: [ { @@ -1607,7 +3500,7 @@ var abi$1 = [ ]; var coinArtifact = { contractName: contractName$1, - abi: abi$1 + abi: abi$4 }; //setting up djed @@ -1616,6 +3509,16 @@ const getDjedContract = (web3, DJED_ADDRESS) => { return djed; }; +const getDjedIsisContract = (web3, DJED_ADDRESS) => { + const djed = new web3.eth.Contract(djedIsisArtifact.abi, DJED_ADDRESS); + return djed; +}; + +const getDjedTefnutContract = (web3, DJED_ADDRESS) => { + const djed = new web3.eth.Contract(djedTefnutArtifact.abi, DJED_ADDRESS); + return djed; +}; + const getCoinContracts = async (djedContract, web3) => { const [stableCoinAddress, reserveCoinAddress] = await Promise.all([ web3Promise$1(djedContract, "stableCoin"), @@ -1636,6 +3539,16 @@ const getDecimals = async (stableCoin, reserveCoin) => { return { scDecimals, rcDecimals }; }; +const checkIfShu = async (djedContract) => { + try { + // Check if scMaxPrice exists on the contract + await djedContract.methods.scMaxPrice(0).call(); + return true; + } catch (e) { + return false; + } +}; + const getCoinDetails = async ( stableCoin, reserveCoin, @@ -1644,6 +3557,9 @@ const getCoinDetails = async ( rcDecimals ) => { try { + const isShu = await checkIfShu(djed); + const priceMethod = isShu ? "scMaxPrice" : "scPrice"; + const [ [scaledNumberSc, unscaledNumberSc], [scaledPriceSc, unscaledPriceSc], @@ -1653,14 +3569,14 @@ const getCoinDetails = async ( scaledScExchangeRate, ] = await Promise.all([ scaledUnscaledPromise(web3Promise$1(stableCoin, "totalSupply"), scDecimals), - scaledUnscaledPromise(web3Promise$1(djed, "scPrice", 0), BC_DECIMALS), + scaledUnscaledPromise(web3Promise$1(djed, priceMethod, 0), BC_DECIMALS), scaledUnscaledPromise( web3Promise$1(reserveCoin, "totalSupply"), rcDecimals ), scaledUnscaledPromise(web3Promise$1(djed, "R", 0), BC_DECIMALS), scaledPromise(web3Promise$1(djed, "rcBuyingPrice", 0), BC_DECIMALS), - scaledPromise(web3Promise$1(djed, "scPrice", 0), BC_DECIMALS), + scaledPromise(web3Promise$1(djed, priceMethod, 0), BC_DECIMALS), ]); // Define default empty value @@ -1668,6 +3584,8 @@ const getCoinDetails = async ( let scaledSellPriceRc = emptyValue; let unscaledSellPriceRc = emptyValue; let percentReserveRatio = emptyValue; + let percentReserveRatioMin = emptyValue; + let percentReserveRatioMax = emptyValue; // Check total reserve coin supply to calculate sell price if (BigInt(unscaledNumberRc) !== 0n) { @@ -1679,14 +3597,25 @@ const getCoinDetails = async ( // Check total stable coin supply to calculate reserve ratio if (BigInt(unscaledNumberSc) !== 0n) { - percentReserveRatio = await percentScaledPromise( - web3Promise$1(djed, "ratio"), - SCALING_DECIMALS - ); + if (isShu) { + const [ratioMin, ratioMax] = await Promise.all([ + percentScaledPromise(web3Promise$1(djed, "ratioMin"), SCALING_DECIMALS), + percentScaledPromise(web3Promise$1(djed, "ratioMax"), SCALING_DECIMALS) + ]); + percentReserveRatioMin = ratioMin; + percentReserveRatioMax = ratioMax; + percentReserveRatio = `${ratioMin} - ${ratioMax}`; + } else { + percentReserveRatio = await percentScaledPromise( + web3Promise$1(djed, "ratio"), + SCALING_DECIMALS + ); + } } // Return the results return { + isShu, scaledNumberSc, unscaledNumberSc, scaledPriceSc, @@ -1696,6 +3625,8 @@ const getCoinDetails = async ( scaledReserveBc, unscaledReserveBc, percentReserveRatio, + percentReserveRatioMin, + percentReserveRatioMax, scaledBuyPriceRc, scaledSellPriceRc, unscaledSellPriceRc, @@ -1714,12 +3645,22 @@ const getSystemParams = async (djed) => { feeUnscaled, treasuryFee, thresholdSupplySC, + initialTreasuryFee, + treasuryRevenueTarget, + treasuryRevenue, + rcMinPrice, + txLimit, ] = await Promise.all([ web3Promise$1(djed, "reserveRatioMin"), web3Promise$1(djed, "reserveRatioMax"), web3Promise$1(djed, "fee"), percentScaledPromise(web3Promise$1(djed, "treasuryFee"), SCALING_DECIMALS), web3Promise$1(djed, "thresholdSupplySC"), + web3Promise$1(djed, "initialTreasuryFee"), + web3Promise$1(djed, "treasuryRevenueTarget"), + web3Promise$1(djed, "treasuryRevenue"), + web3Promise$1(djed, "rcMinPrice"), + web3Promise$1(djed, "txLimit"), ]); return { @@ -1739,6 +3680,12 @@ const getSystemParams = async (djed) => { feeUnscaled, treasuryFee, thresholdSupplySC, + initialTreasuryFee: percentageScale(initialTreasuryFee, SCALING_DECIMALS, true), + initialTreasuryFeeUnscaled: initialTreasuryFee, + treasuryRevenueTarget, + treasuryRevenue, + rcMinPrice, + txLimit, }; }; @@ -1776,148 +3723,433 @@ const getAccountDetails = async ( }; }; +/** + * Utility to listen for Djed contract events + * @param {Object} djedContract - The Web3 contract instance + * @param {Object} callbacks - Object containing callback functions for different events + * @param {Function} callbacks.onBoughtStableCoins - (eventData) => {} + * @param {Function} callbacks.onSoldStableCoins - (eventData) => {} + * @param {Function} callbacks.onBoughtReserveCoins - (eventData) => {} + * @param {Function} callbacks.onSoldReserveCoins - (eventData) => {} + * @param {Function} callbacks.onSoldBothCoins - (eventData) => {} + * @param {Function} callbacks.onError - (error) => {} + */ +const subscribeToDjedEvents = (djedContract, callbacks) => { + const events = [ + { name: "BoughtStableCoins", cb: callbacks.onBoughtStableCoins }, + { name: "SoldStableCoins", cb: callbacks.onSoldStableCoins }, + { name: "BoughtReserveCoins", cb: callbacks.onBoughtReserveCoins }, + { name: "SoldReserveCoins", cb: callbacks.onSoldReserveCoins }, + { name: "SoldBothCoins", cb: callbacks.onSoldBothCoins }, + ]; + + const subscriptions = []; + + events.forEach((event) => { + if (event.cb) { + const sub = djedContract.events[event.name]({ + fromBlock: "latest", + }) + .on("data", (data) => { + event.cb(data.returnValues); + }) + .on("error", (err) => { + if (callbacks.onError) callbacks.onError(err); + else console.error(`Error in ${event.name} subscription:`, err); + }); + subscriptions.push(sub); + } + }); + + return { + unsubscribe: () => { + subscriptions.forEach((sub) => { + if (sub.unsubscribe) sub.unsubscribe(); + }); + }, + }; +}; + +/** + * Utility to fetch past events from the Djed contract + * @param {Object} djedContract - The Web3 contract instance + * @param {string} eventName - Name of the event + * @param {Object} filter - Web3 filter object (e.g., { buyer: '0x...' }) + * @param {number|string} fromBlock - Starting block + * @returns {Promise} - Array of past events + */ +const getPastDjedEvents = async ( + djedContract, + eventName, + filter = {}, + fromBlock = 0 +) => { + try { + return await djedContract.getPastEvents(eventName, { + filter, + fromBlock, + toBlock: "latest", + }); + } catch (error) { + console.error(`Error fetching past events for ${eventName}:`, error); + throw error; + } +}; + +const approveTx = (tokenContract, owner, spender, amount) => { + const data = tokenContract.methods.approve(spender, amount).encodeABI(); + return buildTx(owner, tokenContract.options.address, 0, data); +}; + +const checkAllowance = async (tokenContract, owner, spender) => { + return await tokenContract.methods.allowance(owner, spender).call(); +}; + var contractName = "Oracle"; -var abi = [ +var abi$3 = [ + { + inputs: [ + { + internalType: "address", + name: "_owner", + type: "address" + }, + { + internalType: "string", + name: "_description", + type: "string" + }, + { + internalType: "string", + name: "_termsOfService", + type: "string" + } + ], + stateMutability: "nonpayable", + type: "constructor" + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "uint256", + name: "data", + type: "uint256" + } + ], + name: "DataWritten", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "address", + name: "a", + type: "address" + }, + { + indexed: false, + internalType: "address", + name: "opposer", + type: "address" + } + ], + name: "OppositionAdded", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "address", + name: "a", + type: "address" + }, + { + indexed: false, + internalType: "address", + name: "opposer", + type: "address" + } + ], + name: "OppositionRemoved", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "address", + name: "a", + type: "address" + } + ], + name: "OwnerAdded", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "address", + name: "a", + type: "address" + } + ], + name: "OwnerRemoved", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "address", + name: "a", + type: "address" + }, + { + indexed: false, + internalType: "address", + name: "supporter", + type: "address" + } + ], + name: "SupportAdded", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "address", + name: "a", + type: "address" + }, + { + indexed: false, + internalType: "address", + name: "supporter", + type: "address" + } + ], + name: "SupportRemoved", + type: "event" + }, + { + inputs: [ + ], + name: "acceptTermsOfService", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "", + type: "address" + } + ], + name: "acceptedTermsOfService", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "a", + type: "address" + } + ], + name: "add", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, { inputs: [ - { - internalType: "address", - name: "_owner", - type: "address" - }, - { - internalType: "string", - name: "_description", - type: "string" - }, + ], + name: "description", + outputs: [ { internalType: "string", - name: "_termsOfService", + name: "", type: "string" } ], - stateMutability: "nonpayable", - type: "constructor" + stateMutability: "view", + type: "function" }, { - anonymous: false, inputs: [ + ], + name: "numOwners", + outputs: [ { - indexed: false, internalType: "uint256", - name: "data", + name: "", type: "uint256" } ], - name: "DataWritten", - type: "event" + stateMutability: "view", + type: "function" }, { - anonymous: false, inputs: [ { - indexed: false, internalType: "address", name: "a", type: "address" + } + ], + name: "oppose", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "", + type: "address" }, { - indexed: false, internalType: "address", - name: "opposer", + name: "", type: "address" } ], - name: "OppositionAdded", - type: "event" + name: "opposers", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool" + } + ], + stateMutability: "view", + type: "function" }, { - anonymous: false, inputs: [ { - indexed: false, internalType: "address", - name: "a", + name: "", type: "address" }, { - indexed: false, + internalType: "uint256", + name: "", + type: "uint256" + } + ], + name: "opposing", + outputs: [ + { internalType: "address", - name: "opposer", + name: "", type: "address" } ], - name: "OppositionRemoved", - type: "event" + stateMutability: "view", + type: "function" }, { - anonymous: false, inputs: [ { - indexed: false, internalType: "address", - name: "a", + name: "", type: "address" } ], - name: "OwnerAdded", - type: "event" + name: "oppositionCounter", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" }, { - anonymous: false, inputs: [ { - indexed: false, internalType: "address", - name: "a", + name: "", type: "address" } ], - name: "OwnerRemoved", - type: "event" + name: "owner", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool" + } + ], + stateMutability: "view", + type: "function" }, { - anonymous: false, inputs: [ + ], + name: "readData", + outputs: [ { - indexed: false, - internalType: "address", - name: "a", - type: "address" - }, - { - indexed: false, - internalType: "address", - name: "supporter", - type: "address" + internalType: "uint256", + name: "", + type: "uint256" } ], - name: "SupportAdded", - type: "event" + stateMutability: "view", + type: "function" }, { - anonymous: false, inputs: [ { - indexed: false, internalType: "address", name: "a", type: "address" - }, - { - indexed: false, - internalType: "address", - name: "supporter", - type: "address" } ], - name: "SupportRemoved", - type: "event" + name: "remove", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" }, { inputs: [ + { + internalType: "address", + name: "a", + type: "address" + } ], - name: "acceptTermsOfService", + name: "support", outputs: [ ], stateMutability: "nonpayable", @@ -1931,12 +4163,12 @@ var abi = [ type: "address" } ], - name: "acceptedTermsOfService", + name: "supportCounter", outputs: [ { - internalType: "bool", + internalType: "uint256", name: "", - type: "bool" + type: "uint256" } ], stateMutability: "view", @@ -1946,25 +4178,45 @@ var abi = [ inputs: [ { internalType: "address", - name: "a", + name: "", + type: "address" + }, + { + internalType: "address", + name: "", type: "address" } ], - name: "add", + name: "supporters", outputs: [ + { + internalType: "bool", + name: "", + type: "bool" + } ], - stateMutability: "nonpayable", + stateMutability: "view", type: "function" }, { inputs: [ + { + internalType: "address", + name: "", + type: "address" + }, + { + internalType: "uint256", + name: "", + type: "uint256" + } ], - name: "description", + name: "supporting", outputs: [ { - internalType: "string", + internalType: "address", name: "", - type: "string" + type: "address" } ], stateMutability: "view", @@ -1973,12 +4225,12 @@ var abi = [ { inputs: [ ], - name: "numOwners", + name: "termsOfService", outputs: [ { - internalType: "uint256", + internalType: "string", name: "", - type: "uint256" + type: "string" } ], stateMutability: "view", @@ -1992,7 +4244,7 @@ var abi = [ type: "address" } ], - name: "oppose", + name: "unoppose", outputs: [ ], stateMutability: "nonpayable", @@ -2002,257 +4254,852 @@ var abi = [ inputs: [ { internalType: "address", - name: "", + name: "a", type: "address" + } + ], + name: "unsupport", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_data", + type: "uint256" + } + ], + name: "writeData", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + } +]; +var oracleArtifact = { + contractName: contractName, + abi: abi$3 +}; + +var abi$2 = [ + { + type: "constructor", + inputs: [ + { + name: "_ref", + type: "address", + internalType: "contract IStdReference" }, { - internalType: "address", - name: "", - type: "address" + name: "_decimals", + type: "uint8", + internalType: "uint8" + }, + { + name: "_hebeSwapDecimals", + type: "uint8", + internalType: "uint8" + }, + { + name: "_baseToken", + type: "string", + internalType: "string" + }, + { + name: "_quoteToken", + type: "string", + internalType: "string" } ], - name: "opposers", + stateMutability: "nonpayable" + }, + { + type: "function", + name: "acceptTermsOfService", + inputs: [ + ], + outputs: [ + ], + stateMutability: "nonpayable" + }, + { + type: "function", + name: "baseToken", + inputs: [ + ], outputs: [ { - internalType: "bool", name: "", - type: "bool" + type: "string", + internalType: "string" } ], - stateMutability: "view", - type: "function" + stateMutability: "view" }, { + type: "function", + name: "quoteToken", inputs: [ - { - internalType: "address", - name: "", - type: "address" - }, - { - internalType: "uint256", - name: "", - type: "uint256" - } ], - name: "opposing", outputs: [ { - internalType: "address", name: "", - type: "address" + type: "string", + internalType: "string" } ], - stateMutability: "view", - type: "function" + stateMutability: "view" }, { + type: "function", + name: "readData", inputs: [ - { - internalType: "address", - name: "", - type: "address" - } ], - name: "oppositionCounter", outputs: [ { - internalType: "uint256", name: "", - type: "uint256" + type: "uint256", + internalType: "uint256" } ], - stateMutability: "view", - type: "function" + stateMutability: "view" }, { + type: "function", + name: "ref", inputs: [ - { - internalType: "address", - name: "", - type: "address" - } ], - name: "owner", outputs: [ { - internalType: "bool", name: "", - type: "bool" + type: "address", + internalType: "contract IStdReference" } ], - stateMutability: "view", - type: "function" + stateMutability: "view" }, { + type: "function", + name: "scalingFactor", inputs: [ ], - name: "readData", outputs: [ { - internalType: "uint256", name: "", - type: "uint256" + type: "uint256", + internalType: "uint256" } ], - stateMutability: "view", - type: "function" + stateMutability: "view" + } +]; +var bytecode$2 = { + object: "0x60c060405234620000db5762000b08803803806200001d81620000f7565b928339810160a082820312620000db578151906001600160a01b0382168203620000db576200004f602084016200012c565b6200005d604085016200012c565b60608501516001600160401b039591929190868111620000db5784620000859183016200013b565b936080820151968711620000db57620000ab96620000a492016200013b565b93620003d9565b6040516105d1908162000537823960805181818161037201526103f7015260a05181818161043501526104fe0152f35b600080fd5b50634e487b7160e01b600052604160045260246000fd5b6040519190601f01601f191682016001600160401b038111838210176200011d57604052565b62000127620000e0565b604052565b519060ff82168203620000db57565b81601f82011215620000db578051906001600160401b038211620001bf575b60209062000171601f8401601f19168301620000f7565b93838552828483010111620000db5782906000905b83838310620001a6575050116200019c57505090565b6000918301015290565b8193508281939201015182828801015201839162000186565b620001c9620000e0565b6200015a565b50634e487b7160e01b600052601160045260246000fd5b90600182811c9216801562000218575b60208310146200020257565b634e487b7160e01b600052602260045260246000fd5b91607f1691620001f6565b601f811162000230575050565b60009081805260208220906020601f850160051c8301941062000270575b601f0160051c01915b8281106200026457505050565b81815560010162000257565b90925082906200024e565b90601f821162000289575050565b60019160009083825260208220906020601f850160051c83019410620002cc575b601f0160051c01915b828110620002c15750505050565b8181558301620002b3565b9092508290620002aa565b80519091906001600160401b038111620003c9575b6001906200030681620003008454620001e6565b6200027b565b602080601f83116001146200034457508192939460009262000338575b5050600019600383901b1c191690821b179055565b01519050388062000323565b6001600052601f198316959091907fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6926000905b888210620003b1575050838596971062000397575b505050811b019055565b015160001960f88460031b161c191690553880806200038d565b80878596829496860151815501950193019062000378565b620003d3620000e0565b620002ec565b6080529193929160ff91821690821681811062000526575b0316604d811162000516575b600a0a60a05282516001600160401b03811162000506575b6000906200042f81620004298454620001e6565b62000223565b602080601f8311600114620004775750819062000469959684926200046b575b50508160011b916000199060031b1c1916179055620002d7565b565b0151905038806200044f565b60008052601f198316967f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563929185905b898210620004ed5750509083929160019462000469989910620004d3575b505050811b019055620002d7565b015160001960f88460031b161c19169055388080620004c5565b80600185968294968601518155019501930190620004a7565b62000510620000e0565b62000415565b62000520620001cf565b620003fd565b62000530620001cf565b620003f156fe60806040526004361015610013575b600080fd5b6000803560e01c908163217a4b701461008e5750806321a78f6814610085578063bef55ef31461007c578063c55dae6314610073578063dddd9e961461006a5763ed3437f81461006257600080fd5b61000e6104e5565b5061000e6104d1565b5061000e6104a5565b5061000e6103a1565b5061000e61035b565b346100b957806003193601126100b9576100b56100a961024e565b60405191829182610304565b0390f35b80fd5b90600182811c921680156100ec575b60208310146100d657565b634e487b7160e01b600052602260045260246000fd5b91607f16916100cb565b9060009160005490610107826100bc565b8082529160019081811690811561017d575060011461012557505050565b91929350600080527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563916000925b84841061016557505060209250010190565b80546020858501810191909152909301928101610153565b60ff191660208401525050604001925050565b906000916001908154916101a3836100bc565b8083529281811690811561017d57506001146101be57505050565b80929394506000527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6916000925b8484106101fe57505060209250010190565b805460208585018101919091529093019281016101ec565b90601f8019910116810190811067ffffffffffffffff82111761023857604052565b634e487b7160e01b600052604160045260246000fd5b604051600081600191825492610263846100bc565b808452938181169081156102e7575060011461028a575b5061028792500382610216565b90565b600081815291507fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf65b8483106102cc575061028793505081016020013861027a565b819350908160209254838589010152019101909184926102b3565b94505050505060ff1916602082015261028781604081013861027a565b919091602080825283519081818401526000945b828610610345575050806040939411610338575b601f01601f1916010190565b600083828401015261032c565b8581018201518487016040015294810194610318565b503461000e57600036600319011261000e576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b503461000e5760031960003682011261000e5761045a6103f360606100b5936040518093819263195556f360e21b8352604060048401526103e4604484016100f6565b90838203016024840152610190565b03817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610498575b60009161046a575b50517f000000000000000000000000000000000000000000000000000000000000000090610572565b6040519081529081906020820190565b61048b915060603d8111610491575b6104838183610216565b810190610521565b38610431565b503d610479565b6104a0610565565b610429565b503461000e57600036600319011261000e576100b56040516100a9816104ca816100f6565b0382610216565b503461000e57600036600319011261000e57005b503461000e57600036600319011261000e5760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b9081606091031261000e5760405190606082019082821067ffffffffffffffff83111761023857604091825280518352602081015160208401520151604082015290565b506040513d6000823e3d90fd5b8060001904821181151516610585570290565b634e487b7160e01b600052601160045260246000fdfea264697066735822122053cfb7b37092c28d461cf6387ad085646c5cf4ccd06822d58ce0f7819d82b38b64736f6c634300080d0033", + sourceMap: "120:827:2:-:0;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;-1:-1:-1;;;;;120:827:2;;;;;;;;;;;:::i;:::-;;;;;;:::i;:::-;;;;;-1:-1:-1;;;;;120:827:2;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;:::i;:::-;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;120:827:2;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;120:827:2;;;-1:-1:-1;;;;;120:827:2;;;;;;;;;;:::o;:::-;;;:::i;:::-;;;:::o;:::-;;;;;;;;;;:::o;:::-;;;;;;;;;;;;-1:-1:-1;;;;;120:827:2;;;;;;;;;;;-1:-1:-1;;120:827:2;;;;:::i;:::-;;;;;;;;;;;;;;;-1:-1:-1;120:827:2;;;;;;;;;;;;;;;;:::o;:::-;-1:-1:-1;120:827:2;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;578:22;120:827;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;-1:-1:-1;120:827:2;;;;;;;;;;;;;:::o;:::-;610:24;-1:-1:-1;;120:827:2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;-1:-1:-1;120:827:2;;;;;;;;;;-1:-1:-1;;;;;120:827:2;;;;;;;;;;;;;:::i;:::-;;:::i;:::-;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;120:827:2;;;;;;;;;;;;;:::o;:::-;;;;-1:-1:-1;120:827:2;;;;;610:24;120:827;;-1:-1:-1;;120:827:2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;305:336;488:10;;305:336;;;;120:827;;;;;;;;;;;;305:336;120:827;;;;;;;305:336;120:827;;508:60;;120:827;;-1:-1:-1;;;;;120:827:2;;;;305:336;-1:-1:-1;120:827:2;;;;;;;:::i;:::-;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;305:336::o;120:827::-;;;;-1:-1:-1;120:827:2;;;;;578:22;120:827;;-1:-1:-1;;120:827:2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;:::i;:::-;;;;;;:::i;:::-;;", + linkReferences: { + } +}; +var deployedBytecode$2 = { + object: "0x60806040526004361015610013575b600080fd5b6000803560e01c908163217a4b701461008e5750806321a78f6814610085578063bef55ef31461007c578063c55dae6314610073578063dddd9e961461006a5763ed3437f81461006257600080fd5b61000e6104e5565b5061000e6104d1565b5061000e6104a5565b5061000e6103a1565b5061000e61035b565b346100b957806003193601126100b9576100b56100a961024e565b60405191829182610304565b0390f35b80fd5b90600182811c921680156100ec575b60208310146100d657565b634e487b7160e01b600052602260045260246000fd5b91607f16916100cb565b9060009160005490610107826100bc565b8082529160019081811690811561017d575060011461012557505050565b91929350600080527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563916000925b84841061016557505060209250010190565b80546020858501810191909152909301928101610153565b60ff191660208401525050604001925050565b906000916001908154916101a3836100bc565b8083529281811690811561017d57506001146101be57505050565b80929394506000527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6916000925b8484106101fe57505060209250010190565b805460208585018101919091529093019281016101ec565b90601f8019910116810190811067ffffffffffffffff82111761023857604052565b634e487b7160e01b600052604160045260246000fd5b604051600081600191825492610263846100bc565b808452938181169081156102e7575060011461028a575b5061028792500382610216565b90565b600081815291507fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf65b8483106102cc575061028793505081016020013861027a565b819350908160209254838589010152019101909184926102b3565b94505050505060ff1916602082015261028781604081013861027a565b919091602080825283519081818401526000945b828610610345575050806040939411610338575b601f01601f1916010190565b600083828401015261032c565b8581018201518487016040015294810194610318565b503461000e57600036600319011261000e576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b503461000e5760031960003682011261000e5761045a6103f360606100b5936040518093819263195556f360e21b8352604060048401526103e4604484016100f6565b90838203016024840152610190565b03817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610498575b60009161046a575b50517f000000000000000000000000000000000000000000000000000000000000000090610572565b6040519081529081906020820190565b61048b915060603d8111610491575b6104838183610216565b810190610521565b38610431565b503d610479565b6104a0610565565b610429565b503461000e57600036600319011261000e576100b56040516100a9816104ca816100f6565b0382610216565b503461000e57600036600319011261000e57005b503461000e57600036600319011261000e5760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b9081606091031261000e5760405190606082019082821067ffffffffffffffff83111761023857604091825280518352602081015160208401520151604082015290565b506040513d6000823e3d90fd5b8060001904821181151516610585570290565b634e487b7160e01b600052601160045260246000fdfea264697066735822122053cfb7b37092c28d461cf6387ad085646c5cf4ccd06822d58ce0f7819d82b38b64736f6c634300080d0033", + sourceMap: "120:827:2:-:0;;;;;;;;;-1:-1:-1;120:827:2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;:::i;:::-;;;;:::i;:::-;;;;:::i;:::-;;;;;;;;;;;;;274:24;;:::i;:::-;120:827;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;120:827:2;;;;;-1:-1:-1;;120:827:2;;;-1:-1:-1;;120:827:2:o;:::-;;;;857:10;120:827;;;;;;;:::i;:::-;;;;;;;;;857:10;;;;120:827;;;;;;;;:::o;:::-;;;;;;-1:-1:-1;120:827:2;;;-1:-1:-1;120:827:2;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;-1:-1:-1;274:24:2;;120:827;;;;;;;:::i;:::-;;;;;;;;;274:24;;;;120:827;;;;;;;;;;;;;:::i;:::-;;:::o;:::-;-1:-1:-1;120:827:2;;;-1:-1:-1;;120:827:2;;;;;;;-1:-1:-1;120:827:2;;-1:-1:-1;;120:827:2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;120:827:2;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;120:827:2;;;;;;161:34;-1:-1:-1;;;;;120:827:2;;;;;;;;;;;-1:-1:-1;;120:827:2;;;;;;;895:42;120:827;800:77;120:827;;;;;;;;;;;800:77;;120:827;;800:77;;120:827;;;;;;:::i;:::-;;;;;;;;;;;:::i;:::-;800:77;120:827;800:3;-1:-1:-1;;;;;120:827:2;800:77;;;;;;;120:827;;800:77;;;120:827;;;924:13;895:42;;:::i;:::-;120:827;;;;;;;;;;;;;800:77;;;;;;;;;;;;;;;:::i;:::-;;;;;:::i;:::-;;;;;;;;;;;;:::i;:::-;;;120:827;;;;;;;-1:-1:-1;;120:827:2;;;;;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;;;;-1:-1:-1;;120:827:2;;;;;;;;;;;;-1:-1:-1;;120:827:2;;;;;;;201:38;120:827;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;", + linkReferences: { }, - { - inputs: [ + immutableReferences: { + "131": [ { - internalType: "address", - name: "a", - type: "address" + start: 882, + length: 32 + }, + { + start: 1015, + length: 32 } ], - name: "remove", - outputs: [ + "133": [ + { + start: 1077, + length: 32 + }, + { + start: 1278, + length: 32 + } + ] + } +}; +var methodIdentifiers$2 = { + "acceptTermsOfService()": "dddd9e96", + "baseToken()": "c55dae63", + "quoteToken()": "217a4b70", + "readData()": "bef55ef3", + "ref()": "21a78f68", + "scalingFactor()": "ed3437f8" +}; +var rawMetadata$2 = "{\"compiler\":{\"version\":\"0.8.13+commit.abaa5c0e\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"contract IStdReference\",\"name\":\"_ref\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"_decimals\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"_hebeSwapDecimals\",\"type\":\"uint8\"},{\"internalType\":\"string\",\"name\":\"_baseToken\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"_quoteToken\",\"type\":\"string\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"acceptTermsOfService\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"baseToken\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"quoteToken\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"readData\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"ref\",\"outputs\":[{\"internalType\":\"contract IStdReference\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"scalingFactor\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/HebeSwapOracle.sol\":\"HebeSwapOracle\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[\":@api3dao/=lib/contracts/\",\":@chainlink/contracts/=node_modules/@chainlink/contracts/\",\":@eth-optimism/=node_modules/@eth-optimism/\",\":@hebeswap/=lib/hebeswap-contract/\",\":@openzeppelin/=lib/openzeppelin-contracts/\",\":ds-test/=lib/forge-std/lib/ds-test/src/\",\":forge-std/=lib/forge-std/src/\",\":hebeswap-contract/=lib/hebeswap-contract/\",\":openzeppelin-contracts/=lib/openzeppelin-contracts/\",\":solmate/=lib/solmate/src/\"],\"viaIR\":true},\"sources\":{\"lib/hebeswap-contract/IStdReference.sol\":{\"keccak256\":\"0x805354452e33be1dfd58447a237b6bd506287bd30337543cc1e07e05601e4e18\",\"license\":\"Apache-2.0\",\"urls\":[\"bzz-raw://14662cd18e5e122d927e027d8f2ace81d298f5e9b26b84e07a42cd587711a271\",\"dweb:/ipfs/QmWRwfUpiGXspRSJboXBGXmMzzYbDkT2Hs276rRehbtAkT\"]},\"src/HebeSwapOracle.sol\":{\"keccak256\":\"0x24e9a24e8105104d57c6ad72be5bbfa8c7b9cdb77a27102453bd632aa79fbbea\",\"license\":\"AEL\",\"urls\":[\"bzz-raw://236777fe9d91c7e587a092ce6f2ffcdcadea603211a9327a854d81630a9ee824\",\"dweb:/ipfs/QmQrhn7fNXb2gHDk5YqNv3viTv24RgHqV9EsKWe9pD8kB7\"]},\"src/IOracle.sol\":{\"keccak256\":\"0xbdb82189368be9100ec49015ca5838207a3bc5bfec11543d0aede20811cb07ad\",\"license\":\"AEL\",\"urls\":[\"bzz-raw://d6f64b8238eaa188a9b9d7acac753ba0bfccc770b458be512c37c47bc8cafe4c\",\"dweb:/ipfs/QmWB2nD9chE3EAKYa4joucZUsFstZNJDjRoDbrdXEKkYk1\"]}},\"version\":1}"; +var metadata$2 = { + compiler: { + version: "0.8.13+commit.abaa5c0e" + }, + language: "Solidity", + output: { + abi: [ + { + inputs: [ + { + internalType: "contract IStdReference", + name: "_ref", + type: "address" + }, + { + internalType: "uint8", + name: "_decimals", + type: "uint8" + }, + { + internalType: "uint8", + name: "_hebeSwapDecimals", + type: "uint8" + }, + { + internalType: "string", + name: "_baseToken", + type: "string" + }, + { + internalType: "string", + name: "_quoteToken", + type: "string" + } + ], + stateMutability: "nonpayable", + type: "constructor" + }, + { + inputs: [ + ], + stateMutability: "nonpayable", + type: "function", + name: "acceptTermsOfService" + }, + { + inputs: [ + ], + stateMutability: "view", + type: "function", + name: "baseToken", + outputs: [ + { + internalType: "string", + name: "", + type: "string" + } + ] + }, + { + inputs: [ + ], + stateMutability: "view", + type: "function", + name: "quoteToken", + outputs: [ + { + internalType: "string", + name: "", + type: "string" + } + ] + }, + { + inputs: [ + ], + stateMutability: "view", + type: "function", + name: "readData", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ] + }, + { + inputs: [ + ], + stateMutability: "view", + type: "function", + name: "ref", + outputs: [ + { + internalType: "contract IStdReference", + name: "", + type: "address" + } + ] + }, + { + inputs: [ + ], + stateMutability: "view", + type: "function", + name: "scalingFactor", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ] + } ], - stateMutability: "nonpayable", - type: "function" + devdoc: { + kind: "dev", + methods: { + }, + version: 1 + }, + userdoc: { + kind: "user", + methods: { + }, + version: 1 + } + }, + settings: { + remappings: [ + "@api3dao/=lib/contracts/", + "@chainlink/contracts/=node_modules/@chainlink/contracts/", + "@eth-optimism/=node_modules/@eth-optimism/", + "@hebeswap/=lib/hebeswap-contract/", + "@openzeppelin/=lib/openzeppelin-contracts/", + "ds-test/=lib/forge-std/lib/ds-test/src/", + "forge-std/=lib/forge-std/src/", + "hebeswap-contract/=lib/hebeswap-contract/", + "openzeppelin-contracts/=lib/openzeppelin-contracts/", + "solmate/=lib/solmate/src/" + ], + optimizer: { + enabled: true, + runs: 200 + }, + metadata: { + bytecodeHash: "ipfs" + }, + compilationTarget: { + "src/HebeSwapOracle.sol": "HebeSwapOracle" + }, + evmVersion: "london", + libraries: { + }, + viaIR: true }, + sources: { + "lib/hebeswap-contract/IStdReference.sol": { + keccak256: "0x805354452e33be1dfd58447a237b6bd506287bd30337543cc1e07e05601e4e18", + urls: [ + "bzz-raw://14662cd18e5e122d927e027d8f2ace81d298f5e9b26b84e07a42cd587711a271", + "dweb:/ipfs/QmWRwfUpiGXspRSJboXBGXmMzzYbDkT2Hs276rRehbtAkT" + ], + license: "Apache-2.0" + }, + "src/HebeSwapOracle.sol": { + keccak256: "0x24e9a24e8105104d57c6ad72be5bbfa8c7b9cdb77a27102453bd632aa79fbbea", + urls: [ + "bzz-raw://236777fe9d91c7e587a092ce6f2ffcdcadea603211a9327a854d81630a9ee824", + "dweb:/ipfs/QmQrhn7fNXb2gHDk5YqNv3viTv24RgHqV9EsKWe9pD8kB7" + ], + license: "AEL" + }, + "src/IOracle.sol": { + keccak256: "0xbdb82189368be9100ec49015ca5838207a3bc5bfec11543d0aede20811cb07ad", + urls: [ + "bzz-raw://d6f64b8238eaa188a9b9d7acac753ba0bfccc770b458be512c37c47bc8cafe4c", + "dweb:/ipfs/QmWB2nD9chE3EAKYa4joucZUsFstZNJDjRoDbrdXEKkYk1" + ], + license: "AEL" + } + }, + version: 1 +}; +var id$2 = 2; +var hebeSwapOracleArtifact = { + abi: abi$2, + bytecode: bytecode$2, + deployedBytecode: deployedBytecode$2, + methodIdentifiers: methodIdentifiers$2, + rawMetadata: rawMetadata$2, + metadata: metadata$2, + id: id$2 +}; + +var abi$1 = [ { + type: "constructor", inputs: [ { - internalType: "address", - name: "a", - type: "address" + name: "_dataFeedAddress", + type: "address", + internalType: "address" + }, + { + name: "_decimals", + type: "uint256", + internalType: "uint256" } ], - name: "support", + stateMutability: "nonpayable" + }, + { + type: "function", + name: "acceptTermsOfService", + inputs: [ + ], outputs: [ ], - stateMutability: "nonpayable", - type: "function" + stateMutability: "nonpayable" }, { + type: "function", + name: "readData", inputs: [ - { - internalType: "address", - name: "", - type: "address" - } ], - name: "supportCounter", outputs: [ { - internalType: "uint256", name: "", - type: "uint256" + type: "uint256", + internalType: "uint256" } ], - stateMutability: "view", - type: "function" + stateMutability: "view" }, { + type: "function", + name: "scalingFactor", inputs: [ + ], + outputs: [ { - internalType: "address", name: "", - type: "address" + type: "uint256", + internalType: "uint256" + } + ], + stateMutability: "view" + } +]; +var bytecode$1 = { + object: "0x60a0806040523461010057604081610333803803809161001f8285610117565b8339810103126101005780516001600160a01b0381169190829003610100576020908101515f80546001600160a01b0319168417905560405163313ce56760e01b81529092909190829060049082905afa801561010c575f906100cb575b60ff9150169081039081116100b757604d81116100b757600a0a6080526040516101e4908161014f82396080518181816054015260cf0152f35b634e487b7160e01b5f52601160045260245ffd5b506020813d602011610104575b816100e560209383610117565b81010312610100575160ff811681036101005760ff9061007d565b5f80fd5b3d91506100d8565b6040513d5f823e3d90fd5b601f909101601f19168101906001600160401b0382119082101761013a57604052565b634e487b7160e01b5f52604160045260245ffdfe6080806040526004361015610012575f80fd5b5f3560e01c908163bef55ef31461008d57508063dddd9e961461007b5763ed3437f81461003d575f80fd5b34610077575f3660031901126100775760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b5f80fd5b34610077575f36600319011261007757005b34610077575f366003190112610077575f54633fabe5a360e21b825260a090829060049082906001600160a01b03165afa90811561018c575f91610115575b507f00000000000000000000000000000000000000000000000000000000000000009081156101015760209160405191048152f35b634e487b7160e01b5f52601260045260245ffd5b905060a03d60a011610185575b601f8101601f1916820167ffffffffffffffff8111838210176101715760a0918391604052810103126100775761015881610197565b5061016a608060208301519201610197565b50816100cc565b634e487b7160e01b5f52604160045260245ffd5b503d610122565b6040513d5f823e3d90fd5b519069ffffffffffffffffffff821682036100775756fea26469706673582212209673ddeb55b798f5094586c6147a71d254ed39e9b38245e74cfdcd015b47b0cf64736f6c63430008210033", + sourceMap: "159:564:26:-:0;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;-1:-1:-1;;;;;159:564:26;;;;;;;;;;;;;;-1:-1:-1;159:564:26;;-1:-1:-1;;;;;;159:564:26;;;;;;;-1:-1:-1;;;447:19:26;;159:564;;;;;;;447:19;;159:564;;447:19;;;;;;-1:-1:-1;447:19:26;;;-1:-1:-1;159:564:26;;;;;;;;;;;;;;;;;;;418:62;;159:564;;;;;;;;418:62;159:564;;;;;;;;;;;;;;;-1:-1:-1;159:564:26;;447:19;159:564;;-1:-1:-1;159:564:26;447:19;;159:564;447:19;;159:564;447:19;;;;;;159:564;447:19;;;:::i;:::-;;;159:564;;;;;;;;;;;;;447:19;;;159:564;-1:-1:-1;159:564:26;;447:19;;;-1:-1:-1;447:19:26;;;159:564;;;-1:-1:-1;159:564:26;;;;;;;;;;-1:-1:-1;;159:564:26;;;;-1:-1:-1;;;;;159:564:26;;;;;;;;;;:::o;:::-;;;;-1:-1:-1;159:564:26;;;;;-1:-1:-1;159:564:26", + linkReferences: { + } +}; +var deployedBytecode$1 = { + object: "0x6080806040526004361015610012575f80fd5b5f3560e01c908163bef55ef31461008d57508063dddd9e961461007b5763ed3437f81461003d575f80fd5b34610077575f3660031901126100775760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b5f80fd5b34610077575f36600319011261007757005b34610077575f366003190112610077575f54633fabe5a360e21b825260a090829060049082906001600160a01b03165afa90811561018c575f91610115575b507f00000000000000000000000000000000000000000000000000000000000000009081156101015760209160405191048152f35b634e487b7160e01b5f52601260045260245ffd5b905060a03d60a011610185575b601f8101601f1916820167ffffffffffffffff8111838210176101715760a0918391604052810103126100775761015881610197565b5061016a608060208301519201610197565b50816100cc565b634e487b7160e01b5f52604160045260245ffd5b503d610122565b6040513d5f823e3d90fd5b519069ffffffffffffffffffff821682036100775756fea26469706673582212209673ddeb55b798f5094586c6147a71d254ed39e9b38245e74cfdcd015b47b0cf64736f6c63430008210033", + sourceMap: "159:564:26:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;159:564:26;;;;;;;246:38;159:564;;;;;;;;;;;;;-1:-1:-1;;159:564:26;;;;;;;;;;;-1:-1:-1;;159:564:26;;;;;;-1:-1:-1;;;630:26:26;;;;159:564;;;;;;-1:-1:-1;;;;;159:564:26;630:26;;;;;;;159:564;630:26;;;159:564;700:13;;159:564;;;;;;;;;;;;;;;;;;;;;;;;;;630:26;;;;;;;;;;159:564;;;-1:-1:-1;;159:564:26;;;;;;;;;;;;630:26;159:564;;;;;630:26;;159:564;;;;;;;:::i;:::-;;;;;;;;;;;:::i;:::-;;630:26;;;159:564;;;;;;;;;;;;630:26;;;;;;159:564;;;;;;;;;;;;;;;;;;;:::o", + linkReferences: { + }, + immutableReferences: { + "45104": [ + { + start: 84, + length: 32 }, { - internalType: "address", - name: "", - type: "address" + start: 207, + length: 32 } - ], - name: "supporters", - outputs: [ + ] + } +}; +var methodIdentifiers$1 = { + "acceptTermsOfService()": "dddd9e96", + "readData()": "bef55ef3", + "scalingFactor()": "ed3437f8" +}; +var rawMetadata$1 = "{\"compiler\":{\"version\":\"0.8.33+commit.64118f21\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_dataFeedAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_decimals\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"acceptTermsOfService\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"readData\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"scalingFactor\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/ChainlinkOracle.sol\":\"ChainlinkOracle\"},\"evmVersion\":\"prague\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[\":@api3dao/=lib/contracts/\",\":@chainlink/contracts/=node_modules/@chainlink/contracts/\",\":@eth-optimism/=node_modules/@eth-optimism/\",\":@hebeswap/=lib/hebeswap-contract/\",\":@openzeppelin/=lib/openzeppelin-contracts/\",\":ds-test/=lib/forge-std/lib/ds-test/src/\",\":forge-std/=lib/forge-std/src/\",\":hebeswap-contract/=lib/hebeswap-contract/\",\":openzeppelin-contracts/=lib/openzeppelin-contracts/\",\":solmate/=lib/solmate/src/\"],\"viaIR\":true},\"sources\":{\"node_modules/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol\":{\"keccak256\":\"0x6e6e4b0835904509406b070ee173b5bc8f677c19421b76be38aea3b1b3d30846\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://b3beaa37ee61e4ab615e250fbf01601ae481de843fd0ef55e6b44fd9d5fff8a7\",\"dweb:/ipfs/QmeZUVwd26LzK4Mfp8Zba5JbQNkZFfTzFu1A6FVMMZDg9c\"]},\"src/ChainlinkOracle.sol\":{\"keccak256\":\"0xd3a6904bd77d5ee4219b60b519e323268ac4347db771a43bea2c4e2c58b418ad\",\"license\":\"AEL\",\"urls\":[\"bzz-raw://574ddf2d50bffc03e3457150f00a89105882ec86003405011bca28c76f87e635\",\"dweb:/ipfs/QmXBDr2GGd7nnmaC3tbGPm6ASb2ebuqqds1v3rKxD5aDjw\"]},\"src/IOracle.sol\":{\"keccak256\":\"0xbdb82189368be9100ec49015ca5838207a3bc5bfec11543d0aede20811cb07ad\",\"license\":\"AEL\",\"urls\":[\"bzz-raw://d6f64b8238eaa188a9b9d7acac753ba0bfccc770b458be512c37c47bc8cafe4c\",\"dweb:/ipfs/QmWB2nD9chE3EAKYa4joucZUsFstZNJDjRoDbrdXEKkYk1\"]}},\"version\":1}"; +var metadata$1 = { + compiler: { + version: "0.8.33+commit.64118f21" + }, + language: "Solidity", + output: { + abi: [ + { + inputs: [ + { + internalType: "address", + name: "_dataFeedAddress", + type: "address" + }, + { + internalType: "uint256", + name: "_decimals", + type: "uint256" + } + ], + stateMutability: "nonpayable", + type: "constructor" + }, { - internalType: "bool", - name: "", - type: "bool" + inputs: [ + ], + stateMutability: "nonpayable", + type: "function", + name: "acceptTermsOfService" + }, + { + inputs: [ + ], + stateMutability: "view", + type: "function", + name: "readData", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ] + }, + { + inputs: [ + ], + stateMutability: "view", + type: "function", + name: "scalingFactor", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ] } ], - stateMutability: "view", - type: "function" + devdoc: { + kind: "dev", + methods: { + }, + version: 1 + }, + userdoc: { + kind: "user", + methods: { + }, + version: 1 + } + }, + settings: { + remappings: [ + "@api3dao/=lib/contracts/", + "@chainlink/contracts/=node_modules/@chainlink/contracts/", + "@eth-optimism/=node_modules/@eth-optimism/", + "@hebeswap/=lib/hebeswap-contract/", + "@openzeppelin/=lib/openzeppelin-contracts/", + "ds-test/=lib/forge-std/lib/ds-test/src/", + "forge-std/=lib/forge-std/src/", + "hebeswap-contract/=lib/hebeswap-contract/", + "openzeppelin-contracts/=lib/openzeppelin-contracts/", + "solmate/=lib/solmate/src/" + ], + optimizer: { + enabled: true, + runs: 200 + }, + metadata: { + bytecodeHash: "ipfs" + }, + compilationTarget: { + "src/ChainlinkOracle.sol": "ChainlinkOracle" + }, + evmVersion: "prague", + libraries: { + }, + viaIR: true + }, + sources: { + "node_modules/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol": { + keccak256: "0x6e6e4b0835904509406b070ee173b5bc8f677c19421b76be38aea3b1b3d30846", + urls: [ + "bzz-raw://b3beaa37ee61e4ab615e250fbf01601ae481de843fd0ef55e6b44fd9d5fff8a7", + "dweb:/ipfs/QmeZUVwd26LzK4Mfp8Zba5JbQNkZFfTzFu1A6FVMMZDg9c" + ], + license: "MIT" + }, + "src/ChainlinkOracle.sol": { + keccak256: "0xd3a6904bd77d5ee4219b60b519e323268ac4347db771a43bea2c4e2c58b418ad", + urls: [ + "bzz-raw://574ddf2d50bffc03e3457150f00a89105882ec86003405011bca28c76f87e635", + "dweb:/ipfs/QmXBDr2GGd7nnmaC3tbGPm6ASb2ebuqqds1v3rKxD5aDjw" + ], + license: "AEL" + }, + "src/IOracle.sol": { + keccak256: "0xbdb82189368be9100ec49015ca5838207a3bc5bfec11543d0aede20811cb07ad", + urls: [ + "bzz-raw://d6f64b8238eaa188a9b9d7acac753ba0bfccc770b458be512c37c47bc8cafe4c", + "dweb:/ipfs/QmWB2nD9chE3EAKYa4joucZUsFstZNJDjRoDbrdXEKkYk1" + ], + license: "AEL" + } }, + version: 1 +}; +var id$1 = 26; +var chainlinkOracleArtifact = { + abi: abi$1, + bytecode: bytecode$1, + deployedBytecode: deployedBytecode$1, + methodIdentifiers: methodIdentifiers$1, + rawMetadata: rawMetadata$1, + metadata: metadata$1, + id: id$1 +}; + +var abi = [ { + type: "constructor", inputs: [ { - internalType: "address", - name: "", - type: "address" + name: "_proxyAddress", + type: "address", + internalType: "address" }, { - internalType: "uint256", - name: "", - type: "uint256" - } - ], - name: "supporting", - outputs: [ + name: "_api3Decimals", + type: "uint256", + internalType: "uint256" + }, { - internalType: "address", - name: "", - type: "address" + name: "_decimals", + type: "uint256", + internalType: "uint256" } ], - stateMutability: "view", - type: "function" + stateMutability: "nonpayable" }, { + type: "function", + name: "acceptTermsOfService", inputs: [ ], - name: "termsOfService", outputs: [ - { - internalType: "string", - name: "", - type: "string" - } ], - stateMutability: "view", - type: "function" + stateMutability: "nonpayable" }, { + type: "function", + name: "proxyAddress", inputs: [ - { - internalType: "address", - name: "a", - type: "address" - } ], - name: "unoppose", outputs: [ + { + name: "", + type: "address", + internalType: "address" + } ], - stateMutability: "nonpayable", - type: "function" + stateMutability: "view" }, { + type: "function", + name: "readData", inputs: [ - { - internalType: "address", - name: "a", - type: "address" - } ], - name: "unsupport", outputs: [ + { + name: "", + type: "uint256", + internalType: "uint256" + } ], - stateMutability: "nonpayable", - type: "function" + stateMutability: "view" }, { + type: "function", + name: "scalingFactor", inputs: [ - { - internalType: "uint256", - name: "_data", - type: "uint256" - } ], - name: "writeData", outputs: [ + { + name: "", + type: "uint256", + internalType: "uint256" + } ], - stateMutability: "nonpayable", - type: "function" + stateMutability: "view" } ]; -var oracleArtifact = { - contractName: contractName, - abi: abi +var bytecode = { + object: "0x60c060405234156100105760006000fd5b6103b28038038060c00160c0811067ffffffffffffffff8211171561003157fe5b8060405250808260c039606081121561004a5760006000fd5b505060c05173ffffffffffffffffffffffffffffffffffffffff8116811415156100745760006000fd5b60e0516100856101005182846100ba565b505060805160a0516102cc806100e6600039818061011c528061029a52508280606a52806101ed5250806000f35050506100e4565b80608052818310156100c857fe5b818303604d8111156100d657fe5b80600a0a60a052505b505050565bfe6080604052600436101515610149576000803560e01c6323f5c02d81146100465763bef55ef381146100985763dddd9e9681146100d35763ed3437f881146100f857610146565b3415610050578182fd5b61005b366004610153565b61006482610196565b8061008f7f000000000000000000000000000000000000000000000000000000000000000083610169565b0381f350610146565b34156100a2578182fd5b6100ad366004610153565b6100b56101e1565b6100be83610196565b806100c98383610184565b0381f35050610146565b34156100dd578182fd5b6100e8366004610153565b816100f283610196565bf3610146565b3415610102578182fd5b61010d366004610153565b61011682610196565b806101417f000000000000000000000000000000000000000000000000000000000000000083610184565b0381f3505b50505b60006000fd6102cb565b600081830312156101645760006000fd5b5b5050565b60006020820190506001600160a01b03831682525b92915050565b60006020820190508282525b92915050565b6000604051905081810181811067ffffffffffffffff821117156101b657fe5b80604052505b919050565b60008160001904831182151516156101d557fe5b82820290505b92915050565b60006001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016803b1515610219578182fd5b6040516315f789a960e21b8152604081600483855afa9150811515610240573d83843e3d83fd5b82821561029557601f19601f3d011682016040526040823d8401031215610265578384fd5b815180601b0b81141515610277578485fd5b602083015163ffffffff81168114151561028f578586fd5b50809150505b6102c27f000000000000000000000000000000000000000000000000000000000000000082601b0b6101c1565b93505050505b90565b", + sourceMap: "", + linkReferences: { + } +}; +var deployedBytecode = { + object: "0x", + sourceMap: "", + linkReferences: { + } +}; +var methodIdentifiers = { + "acceptTermsOfService()": "dddd9e96", + "proxyAddress()": "23f5c02d", + "readData()": "bef55ef3", + "scalingFactor()": "ed3437f8" +}; +var rawMetadata = "{\"compiler\":{\"version\":\"0.7.6+commit.7338295f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_proxyAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_api3Decimals\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_decimals\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"acceptTermsOfService\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"proxyAddress\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"readData\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"scalingFactor\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/API3Oracle.sol\":\"API3Oracle\"},\"evmVersion\":\"istanbul\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[\":@api3dao/=lib/contracts/\",\":@chainlink/contracts/=node_modules/@chainlink/contracts/\",\":@eth-optimism/=node_modules/@eth-optimism/\",\":@hebeswap/=lib/hebeswap-contract/\",\":@openzeppelin/=lib/openzeppelin-contracts/\",\":ds-test/=lib/forge-std/lib/ds-test/src/\",\":forge-std/=lib/forge-std/src/\",\":hebeswap-contract/=lib/hebeswap-contract/\",\":openzeppelin-contracts/=lib/openzeppelin-contracts/\",\":solmate/=lib/solmate/src/\"],\"viaIR\":true},\"sources\":{\"lib/contracts/contracts/v0.7/interfaces/IProxy.sol\":{\"keccak256\":\"0xb58d1bf2f49358e1a9313aa219df61458778f1c08019cb8d617ad1881a12c39f\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://5553487e888d4f8f5952282f6998b0272127bedfc74cb229e7b8e14636b1ac38\",\"dweb:/ipfs/QmbtEaueqxcfVNwPzTxsRdoBwQKWqcv5UUq5o79o6tCveL\"]},\"src/API3Oracle.sol\":{\"keccak256\":\"0xebf21858eba51f9ac83d4f6104bd076186de755a5342c834544b0a270d32d27b\",\"license\":\"AEL\",\"urls\":[\"bzz-raw://35ada8a00d86957055fb18b1ae7435984c12d8c4ea8b12507458a723af2d1caa\",\"dweb:/ipfs/QmRkz5BKkRDZ3uScuZZQLZ6M2oHxsoud8Xpws9ToPwx1Ub\"]}},\"version\":1}"; +var metadata = { + compiler: { + version: "0.7.6+commit.7338295f" + }, + language: "Solidity", + output: { + abi: [ + { + inputs: [ + { + internalType: "address", + name: "_proxyAddress", + type: "address" + }, + { + internalType: "uint256", + name: "_api3Decimals", + type: "uint256" + }, + { + internalType: "uint256", + name: "_decimals", + type: "uint256" + } + ], + stateMutability: "nonpayable", + type: "constructor" + }, + { + inputs: [ + ], + stateMutability: "nonpayable", + type: "function", + name: "acceptTermsOfService" + }, + { + inputs: [ + ], + stateMutability: "view", + type: "function", + name: "proxyAddress", + outputs: [ + { + internalType: "address", + name: "", + type: "address" + } + ] + }, + { + inputs: [ + ], + stateMutability: "view", + type: "function", + name: "readData", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ] + }, + { + inputs: [ + ], + stateMutability: "view", + type: "function", + name: "scalingFactor", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ] + } + ], + devdoc: { + kind: "dev", + methods: { + }, + version: 1 + }, + userdoc: { + kind: "user", + methods: { + }, + version: 1 + } + }, + settings: { + remappings: [ + "@api3dao/=lib/contracts/", + "@chainlink/contracts/=node_modules/@chainlink/contracts/", + "@eth-optimism/=node_modules/@eth-optimism/", + "@hebeswap/=lib/hebeswap-contract/", + "@openzeppelin/=lib/openzeppelin-contracts/", + "ds-test/=lib/forge-std/lib/ds-test/src/", + "forge-std/=lib/forge-std/src/", + "hebeswap-contract/=lib/hebeswap-contract/", + "openzeppelin-contracts/=lib/openzeppelin-contracts/", + "solmate/=lib/solmate/src/" + ], + optimizer: { + enabled: true, + runs: 200 + }, + metadata: { + bytecodeHash: "ipfs" + }, + compilationTarget: { + "src/API3Oracle.sol": "API3Oracle" + }, + evmVersion: "istanbul", + libraries: { + }, + viaIR: true + }, + sources: { + "lib/contracts/contracts/v0.7/interfaces/IProxy.sol": { + keccak256: "0xb58d1bf2f49358e1a9313aa219df61458778f1c08019cb8d617ad1881a12c39f", + urls: [ + "bzz-raw://5553487e888d4f8f5952282f6998b0272127bedfc74cb229e7b8e14636b1ac38", + "dweb:/ipfs/QmbtEaueqxcfVNwPzTxsRdoBwQKWqcv5UUq5o79o6tCveL" + ], + license: "MIT" + }, + "src/API3Oracle.sol": { + keccak256: "0xebf21858eba51f9ac83d4f6104bd076186de755a5342c834544b0a270d32d27b", + urls: [ + "bzz-raw://35ada8a00d86957055fb18b1ae7435984c12d8c4ea8b12507458a723af2d1caa", + "dweb:/ipfs/QmRkz5BKkRDZ3uScuZZQLZ6M2oHxsoud8Xpws9ToPwx1Ub" + ], + license: "AEL" + } + }, + version: 1 +}; +var id = 2; +var api3OracleArtifact = { + abi: abi, + bytecode: bytecode, + deployedBytecode: deployedBytecode, + methodIdentifiers: methodIdentifiers, + rawMetadata: rawMetadata, + metadata: metadata, + id: id }; const getOracleAddress = async (djedContract) => { @@ -2266,4 +5113,26 @@ const getOracleContract = (web3, oracleAddress, msgSender) => { return oracle; }; -export { FEE_UI_UNSCALED, appendFees, buyRcTx, buyScTx, calculateBcUsdEquivalent, calculateFutureScPrice, calculateIsRatioAboveMin, calculateIsRatioBelowMax, calculateRcUsdEquivalent, calculateTxFees, convertToBC, deductFees, getAccountDetails, getBcUsdEquivalent, getCoinContracts, getCoinDetails, getDecimals, getDjedContract, getFees, getOracleAddress, getOracleContract, getRcUsdEquivalent, getScAdaEquivalent, getSystemParams, getWeb3, isTxLimitReached, promiseTx, scalingFactor, sellRcTx, sellScTx, tradeDataPriceBuyRc, tradeDataPriceBuySc, tradeDataPriceCore, tradeDataPriceSellRc, tradeDataPriceSellSc, verifyTx }; +const getHebeSwapOracleContract = (web3, oracleAddress, msgSender) => { + const oracle = new web3.eth.Contract(hebeSwapOracleArtifact.abi, oracleAddress, { + from: msgSender + }); + return oracle; +}; + +const getChainlinkOracleContract = (web3, oracleAddress, msgSender) => { + const oracle = new web3.eth.Contract(chainlinkOracleArtifact.abi, oracleAddress, { + from: msgSender + }); + return oracle; +}; + + +const getAPI3OracleContract = (web3, oracleAddress, msgSender) => { + const oracle = new web3.eth.Contract(api3OracleArtifact.abi, oracleAddress, { + from: msgSender + }); + return oracle; +}; + +export { FEE_UI_UNSCALED, appendFees, approveTx, buyRcIsisTx, buyRcTx, buyScIsisTx, buyScTx, calculateBcUsdEquivalent, calculateFutureScPrice, calculateIsRatioAboveMin, calculateIsRatioBelowMax, calculateRcUsdEquivalent, calculateTxFees, checkAllowance, convertToBC, deductFees, getAPI3OracleContract, getAccountDetails, getBcUsdEquivalent, getChainlinkOracleContract, getCoinContracts, getCoinDetails, getDecimals, getDjedContract, getDjedIsisContract, getDjedTefnutContract, getFees, getHebeSwapOracleContract, getOracleAddress, getOracleContract, getPastDjedEvents, getRcUsdEquivalent, getScAdaEquivalent, getSystemParams, getWeb3, isTxLimitReached, promiseTx, scalingFactor, sellBothIsisTx, sellBothTx, sellRcIsisTx, sellRcTx, sellScIsisTx, sellScTx, subscribeToDjedEvents, tradeDataPriceBuyRc, tradeDataPriceBuySc, tradeDataPriceCore, tradeDataPriceSellBoth, tradeDataPriceSellRc, tradeDataPriceSellSc, verifyTx }; diff --git a/djed-sdk/dist/umd/index.js b/djed-sdk/dist/umd/index.js index 24bf322..75f8678 100644 --- a/djed-sdk/dist/umd/index.js +++ b/djed-sdk/dist/umd/index.js @@ -257,10 +257,11 @@ * @param {*} amountUSD * @param {*} totalSCSupply * @param {*} thresholdSCSupply + * @param {*} txLimit * @returns */ - const isTxLimitReached = (amountUSD, totalSCSupply, thresholdSCSupply) => - amountUSD > TRANSACTION_USD_LIMIT && + const isTxLimitReached = (amountUSD, totalSCSupply, thresholdSCSupply, txLimit) => + (BigInt(amountUSD) > BigInt(txLimit || TRANSACTION_USD_LIMIT)) && BigInt(totalSCSupply) >= BigInt(thresholdSCSupply); const promiseTx = (isWalletConnected, tx, signer) => { @@ -348,6 +349,26 @@ } }; + /** + * Function that returns the correct price method name based on the contract version and operation + * @param {*} djed Djed contract + * @param {*} operation 'buySC', 'sellSC', 'buyRC', 'sellRC' + * @returns + */ + const getPriceMethod = async (djed, operation) => { + const isShu = await djed.methods.scMaxPrice(0).call().then(() => true).catch(() => false); + + if (!isShu) return "scPrice"; + + switch (operation) { + case 'buySC': return "scMaxPrice"; + case 'sellSC': return "scMinPrice"; + case 'buyRC': return "scMinPrice"; + case 'sellRC': return "scMaxPrice"; + default: return "scPrice"; + } + }; + /** * Function that calculates fees and how much BC (totalBCAmount) user should pay to receive desired amount of reserve coin * @param {*} djed DjedContract @@ -357,6 +378,7 @@ */ const tradeDataPriceBuyRc = async (djed, rcDecimals, amountScaled) => { try { + const scMethod = await getPriceMethod(djed, 'buyRC'); const data = await tradeDataPriceCore( djed, "rcBuyingPrice", @@ -383,6 +405,7 @@ const tradeDataPriceSellRc = async (djed, rcDecimals, amountScaled) => { try { + const scMethod = await getPriceMethod(djed, 'sellRC'); const data = await tradeDataPriceCore( djed, "rcTargetPrice", @@ -432,9 +455,10 @@ */ const tradeDataPriceBuySc = async (djed, scDecimals, amountScaled) => { try { + const method = await getPriceMethod(djed, 'buySC'); const data = await tradeDataPriceCore( djed, - "scPrice", + method, scDecimals, amountScaled ); @@ -465,9 +489,10 @@ */ const tradeDataPriceSellSc = async (djed, scDecimals, amountScaled) => { try { + const method = await getPriceMethod(djed, 'sellSC'); const data = await tradeDataPriceCore( djed, - "scPrice", + method, scDecimals, amountScaled ); @@ -547,8 +572,169 @@ } }; - var contractName$2 = "Djed"; - var abi$2 = [ + /** + * Function that calculates fees and how much BC (totalBCAmount) user will receive if he sells desired amount of stable coin and reserve coin + * @param {*} djed DjedContract + * @param {*} scDecimals Stable coin decimals + * @param {*} rcDecimals Reserve coin decimals + * @param {*} amountScScaled Stable coin amount that user wants to sell + * @param {*} amountRcScaled Reserve coin amount that user wants to sell + * @returns + */ + const tradeDataPriceSellBoth = async ( + djed, + scDecimals, + rcDecimals, + amountScScaled, + amountRcScaled + ) => { + try { + const scPriceMethod = await getPriceMethod(djed, 'sellSC'); + const [scPriceData, rcPriceData] = await Promise.all([ + scaledUnscaledPromise(web3Promise$1(djed, scPriceMethod, 0), BC_DECIMALS), + scaledUnscaledPromise(web3Promise$1(djed, "rcTargetPrice", 0), BC_DECIMALS), + ]); + + const amountScUnscaled = decimalUnscaling(amountScScaled, scDecimals); + const amountRcUnscaled = decimalUnscaling(amountRcScaled, rcDecimals); + + const scValueBC = convertToBC( + amountScUnscaled, + scPriceData[1], + scDecimals + ); + const rcValueBC = convertToBC( + amountRcUnscaled, + rcPriceData[1], + rcDecimals + ); + + const totalValueBC = (scValueBC + rcValueBC).toString(); + + const { treasuryFee, fee } = await getFees(djed); + const totalBCAmount = deductFees(totalValueBC, fee, treasuryFee); + + return { + scPriceScaled: scPriceData[0], + scPriceUnscaled: scPriceData[1], + rcPriceScaled: rcPriceData[0], + rcPriceUnscaled: rcPriceData[1], + amountScUnscaled, + amountRcUnscaled, + totalBCScaled: decimalScaling(totalBCAmount.toString(), BC_DECIMALS), + totalBCUnscaled: totalBCAmount.toString(), + }; + } catch (error) { + console.error("Error in tradeDataPriceSellBoth:", error); + } + }; + + /** + * Function to sell both stablecoins and reservecoins + * @param {*} djed DjedContract + * @param {*} account User address + * @param {*} amountSC Unscaled amount of stablecoins to sell + * @param {*} amountRC Unscaled amount of reservecoins to sell + * @param {*} UI UI address for fee + * @param {*} DJED_ADDRESS Address of Djed contract + * @returns + */ + const sellBothTx = ( + djed, + account, + amountSC, + amountRC, + UI, + DJED_ADDRESS + ) => { + const data = djed.methods + .sellBothCoins(amountSC, amountRC, account, FEE_UI_UNSCALED, UI) + .encodeABI(); + return buildTx(account, DJED_ADDRESS, 0, data); + }; + + // # ISIS / TEFNUT Transaction Functions (ERC20 Base Asset) + + /** + * Buy StableCoins (Isis/Tefnut Variant - ERC20 Base Asset) + * Note: Caller must APPROVE the Djed contract to spend `amountBC` of the Base Asset before calling this. + * @param {object} djed The DjedContract instance + * @param {string} payer The address paying the Base Asset + * @param {string} receiver The address receiving the StableCoins + * @param {string} amountBC The amount of Base Asset to pay (in wei/smallest unit) + * @param {string} UI The UI address + * @param {string} DJED_ADDRESS The Djed contract address + * @returns {object} The transaction object + */ + const buyScIsisTx = (djed, payer, receiver, amountBC, UI, DJED_ADDRESS) => { + // Signature: buyStableCoins(uint256 amountBC, address receiver, uint256 feeUI, address ui) + const data = djed.methods + .buyStableCoins(amountBC, receiver, FEE_UI_UNSCALED, UI) + .encodeABI(); + + // Value is 0 because Base Asset is ERC20 transferFrom, not msg.value + return buildTx(payer, DJED_ADDRESS, 0, data); + }; + + /** + * Sell StableCoins (Isis/Tefnut Variant) + * Note: Same logic as Osiris, but ensuring naming consistency if needed. + * But functionally, sellStableCoins signature is: sellStableCoins(uint256 amountSC, address receiver, uint256 feeUI, address ui) + * which matches Osiris. Using the same function is fine, but we provide an alias for clarity. + */ + const sellScIsisTx = (djed, account, amountSC, UI, DJED_ADDRESS) => { + // Signature: sellStableCoins(uint256 amountSC, address receiver, uint256 feeUI, address ui) + // This is identical to Osiris, so we can reuse the logic or just wrap it. + // However, the internal implementation of Djed Isis would transfer ERC20 back to user. + const data = djed.methods + .sellStableCoins(amountSC, account, FEE_UI_UNSCALED, UI) + .encodeABI(); + return buildTx(account, DJED_ADDRESS, 0, data); + }; + + /** + * Buy ReserveCoins (Isis/Tefnut Variant - ERC20 Base Asset) + * Note: Caller must APPROVE the Djed contract to spend `amountBC` of the Base Asset before calling this. + * @param {object} djed The DjedContract instance + * @param {string} payer The address paying the Base Asset + * @param {string} receiver The address receiving the ReserveCoins + * @param {string} amountBC The amount of Base Asset to pay (in wei/smallest unit) + * @param {string} UI The UI address + * @param {string} DJED_ADDRESS The Djed contract address + * @returns {object} The transaction object + */ + const buyRcIsisTx = (djed, payer, receiver, amountBC, UI, DJED_ADDRESS) => { + // Signature: buyReserveCoins(uint256 amountBC, address receiver, uint256 feeUI, address ui) + const data = djed.methods + .buyReserveCoins(amountBC, receiver, FEE_UI_UNSCALED, UI) + .encodeABI(); + + return buildTx(payer, DJED_ADDRESS, 0, data); + }; + + const sellRcIsisTx = (djed, account, amountRC, UI, DJED_ADDRESS) => { + // Signature: sellReserveCoins(uint256 amountRC, address receiver, uint256 feeUI, address ui) + const data = djed.methods + .sellReserveCoins(amountRC, account, FEE_UI_UNSCALED, UI) + .encodeABI(); + return buildTx(account, DJED_ADDRESS, 0, data); + }; + + /** + * Sell Both Coins (Isis/Tefnut Variant) + * Note: Same logic as Osiris. + */ + const sellBothIsisTx = (djed, account, amountSC, amountRC, UI, DJED_ADDRESS) => { + // Signature: sellBothCoins(uint256 amountSC, uint256 amountRC, address receiver, uint256 feeUI, address ui) + // Actually, check Djed.sol: sellBothCoins(uint256 amountSC, uint256 amountRC, address receiver, uint256 feeUI, address ui) + const data = djed.methods + .sellBothCoins(amountSC, amountRC, account, FEE_UI_UNSCALED, UI) + .encodeABI(); + return buildTx(account, DJED_ADDRESS, 0, data); + }; + + var contractName$4 = "Djed"; + var abi$7 = [ { inputs: [ { @@ -1271,95 +1457,35 @@ ], stateMutability: "view", type: "function" - } - ]; - var djedArtifact = { - contractName: contractName$2, - abi: abi$2 - }; - - var contractName$1 = "Coin"; - var abi$1 = [ - { - inputs: [ - { - internalType: "string", - name: "name", - type: "string" - }, - { - internalType: "string", - name: "symbol", - type: "string" - } - ], - stateMutability: "nonpayable", - type: "constructor" }, { - anonymous: false, inputs: [ { - indexed: true, - internalType: "address", - name: "owner", - type: "address" - }, - { - indexed: true, - internalType: "address", - name: "spender", - type: "address" - }, - { - indexed: false, internalType: "uint256", - name: "value", + name: "_currentPaymentAmount", type: "uint256" } ], - name: "Approval", - type: "event" - }, - { - anonymous: false, - inputs: [ - { - indexed: true, - internalType: "address", - name: "from", - type: "address" - }, - { - indexed: true, - internalType: "address", - name: "to", - type: "address" - }, + name: "scMaxPrice", + outputs: [ { - indexed: false, internalType: "uint256", - name: "value", + name: "", type: "uint256" } ], - name: "Transfer", - type: "event" + stateMutability: "view", + type: "function" }, { inputs: [ { - internalType: "address", - name: "owner", - type: "address" - }, - { - internalType: "address", - name: "spender", - type: "address" + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" } ], - name: "allowance", + name: "scMinPrice", outputs: [ { internalType: "uint256", @@ -1372,37 +1498,22 @@ }, { inputs: [ - { - internalType: "address", - name: "spender", - type: "address" - }, - { - internalType: "uint256", - name: "amount", - type: "uint256" - } ], - name: "approve", + name: "ratioMax", outputs: [ { - internalType: "bool", + internalType: "uint256", name: "", - type: "bool" + type: "uint256" } ], - stateMutability: "nonpayable", + stateMutability: "view", type: "function" }, { inputs: [ - { - internalType: "address", - name: "account", - type: "address" - } ], - name: "balanceOf", + name: "ratioMin", outputs: [ { internalType: "uint256", @@ -1415,55 +1526,1837 @@ }, { inputs: [ - { - internalType: "address", - name: "spender", - type: "address" - }, - { - internalType: "uint256", - name: "subtractedValue", - type: "uint256" - } ], - name: "decreaseAllowance", + name: "updateOracleValues", outputs: [ - { - internalType: "bool", - name: "", - type: "bool" - } ], stateMutability: "nonpayable", type: "function" - }, + } + ]; + var djedArtifact = { + contractName: contractName$4, + abi: abi$7 + }; + + var contractName$3 = "Djed"; + var abi$6 = [ { inputs: [ { internalType: "address", - name: "spender", + name: "oracleAddress", type: "address" }, { internalType: "uint256", - name: "addedValue", + name: "_scalingFactor", type: "uint256" - } - ], - name: "increaseAllowance", - outputs: [ + }, { - internalType: "bool", - name: "", - type: "bool" + internalType: "address", + name: "_treasury", + type: "address" + }, + { + internalType: "uint256", + name: "_initialTreasuryFee", + type: "uint256" + }, + { + internalType: "uint256", + name: "_treasuryRevenueTarget", + type: "uint256" + }, + { + internalType: "uint256", + name: "_reserveRatioMin", + type: "uint256" + }, + { + internalType: "uint256", + name: "_reserveRatioMax", + type: "uint256" + }, + { + internalType: "uint256", + name: "_fee", + type: "uint256" + }, + { + internalType: "uint256", + name: "_thresholdSupplySC", + type: "uint256" + }, + { + internalType: "uint256", + name: "_rcMinPrice", + type: "uint256" + }, + { + internalType: "uint256", + name: "_txLimit", + type: "uint256" } ], - stateMutability: "nonpayable", - type: "function" + stateMutability: "payable", + type: "constructor" }, { + anonymous: false, inputs: [ - ], + { + indexed: true, + internalType: "address", + name: "buyer", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "receiver", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "amountRC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountBC", + type: "uint256" + } + ], + name: "BoughtReserveCoins", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "buyer", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "receiver", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "amountSC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountBC", + type: "uint256" + } + ], + name: "BoughtStableCoins", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "seller", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "receiver", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "amountSC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountRC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountBC", + type: "uint256" + } + ], + name: "SoldBothCoins", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "seller", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "receiver", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "amountRC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountBC", + type: "uint256" + } + ], + name: "SoldReserveCoins", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "seller", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "receiver", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "amountSC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountBC", + type: "uint256" + } + ], + name: "SoldStableCoins", + type: "event" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "E", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "L", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "R", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "amount", + type: "uint256" + }, + { + internalType: "address", + name: "receiver", + type: "address" + }, + { + internalType: "uint256", + name: "fee_ui", + type: "uint256" + }, + { + internalType: "address", + name: "ui", + type: "address" + } + ], + name: "buyReserveCoins", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "amount", + type: "uint256" + }, + { + internalType: "address", + name: "receiver", + type: "address" + }, + { + internalType: "uint256", + name: "feeUI", + type: "uint256" + }, + { + internalType: "address", + name: "ui", + type: "address" + } + ], + name: "buyStableCoins", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + ], + name: "fee", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "initialTreasuryFee", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "oracle", + outputs: [ + { + internalType: "contract IFreeOracle", + name: "", + type: "address" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "ratio", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "rcBuyingPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "rcDecimalScalingFactor", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "rcMinPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "rcTargetPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "reserveCoin", + outputs: [ + { + internalType: "contract Coin", + name: "", + type: "address" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "reserveRatioMax", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "reserveRatioMin", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "scDecimalScalingFactor", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "scPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "scalingFactor", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "amountSC", + type: "uint256" + }, + { + internalType: "uint256", + name: "amountRC", + type: "uint256" + }, + { + internalType: "address", + name: "receiver", + type: "address" + }, + { + internalType: "uint256", + name: "fee_ui", + type: "uint256" + }, + { + internalType: "address", + name: "ui", + type: "address" + } + ], + name: "sellBothCoins", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "amountRC", + type: "uint256" + }, + { + internalType: "address", + name: "receiver", + type: "address" + }, + { + internalType: "uint256", + name: "fee_ui", + type: "uint256" + }, + { + internalType: "address", + name: "ui", + type: "address" + } + ], + name: "sellReserveCoins", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "amountSC", + type: "uint256" + }, + { + internalType: "address", + name: "receiver", + type: "address" + }, + { + internalType: "uint256", + name: "feeUI", + type: "uint256" + }, + { + internalType: "address", + name: "ui", + type: "address" + } + ], + name: "sellStableCoins", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + ], + name: "stableCoin", + outputs: [ + { + internalType: "contract Coin", + name: "", + type: "address" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "thresholdSupplySC", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "treasury", + outputs: [ + { + internalType: "address", + name: "", + type: "address" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "treasuryFee", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "treasuryRevenue", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "treasuryRevenueTarget", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "txLimit", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "scMaxPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "scMinPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "ratioMax", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "ratioMin", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "updateOracleValues", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + } + ]; + var djedIsisArtifact = { + contractName: contractName$3, + abi: abi$6 + }; + + var contractName$2 = "Djed"; + var abi$5 = [ + { + inputs: [ + { + internalType: "address", + name: "oracleAddress", + type: "address" + }, + { + internalType: "uint256", + name: "_scalingFactor", + type: "uint256" + }, + { + internalType: "address", + name: "_treasury", + type: "address" + }, + { + internalType: "uint256", + name: "_initialTreasuryFee", + type: "uint256" + }, + { + internalType: "uint256", + name: "_treasuryRevenueTarget", + type: "uint256" + }, + { + internalType: "uint256", + name: "_reserveRatioMin", + type: "uint256" + }, + { + internalType: "uint256", + name: "_reserveRatioMax", + type: "uint256" + }, + { + internalType: "uint256", + name: "_fee", + type: "uint256" + }, + { + internalType: "uint256", + name: "_thresholdSupplySC", + type: "uint256" + }, + { + internalType: "uint256", + name: "_rcMinPrice", + type: "uint256" + }, + { + internalType: "uint256", + name: "_txLimit", + type: "uint256" + } + ], + stateMutability: "payable", + type: "constructor" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "buyer", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "receiver", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "amountRC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountBC", + type: "uint256" + } + ], + name: "BoughtReserveCoins", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "buyer", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "receiver", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "amountSC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountBC", + type: "uint256" + } + ], + name: "BoughtStableCoins", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "seller", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "receiver", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "amountSC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountRC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountBC", + type: "uint256" + } + ], + name: "SoldBothCoins", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "seller", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "receiver", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "amountRC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountBC", + type: "uint256" + } + ], + name: "SoldReserveCoins", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "seller", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "receiver", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "amountSC", + type: "uint256" + }, + { + indexed: false, + internalType: "uint256", + name: "amountBC", + type: "uint256" + } + ], + name: "SoldStableCoins", + type: "event" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "E", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "L", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "R", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "amount", + type: "uint256" + }, + { + internalType: "address", + name: "receiver", + type: "address" + }, + { + internalType: "uint256", + name: "fee_ui", + type: "uint256" + }, + { + internalType: "address", + name: "ui", + type: "address" + } + ], + name: "buyReserveCoins", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "amount", + type: "uint256" + }, + { + internalType: "address", + name: "receiver", + type: "address" + }, + { + internalType: "uint256", + name: "feeUI", + type: "uint256" + }, + { + internalType: "address", + name: "ui", + type: "address" + } + ], + name: "buyStableCoins", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + ], + name: "fee", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "initialTreasuryFee", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "oracle", + outputs: [ + { + internalType: "contract IFreeOracle", + name: "", + type: "address" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "ratio", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "rcBuyingPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "rcDecimalScalingFactor", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "rcMinPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "rcTargetPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "reserveCoin", + outputs: [ + { + internalType: "contract Coin", + name: "", + type: "address" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "reserveRatioMax", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "reserveRatioMin", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "scDecimalScalingFactor", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "scPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "scalingFactor", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "amountSC", + type: "uint256" + }, + { + internalType: "uint256", + name: "amountRC", + type: "uint256" + }, + { + internalType: "address", + name: "receiver", + type: "address" + }, + { + internalType: "uint256", + name: "fee_ui", + type: "uint256" + }, + { + internalType: "address", + name: "ui", + type: "address" + } + ], + name: "sellBothCoins", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "amountRC", + type: "uint256" + }, + { + internalType: "address", + name: "receiver", + type: "address" + }, + { + internalType: "uint256", + name: "fee_ui", + type: "uint256" + }, + { + internalType: "address", + name: "ui", + type: "address" + } + ], + name: "sellReserveCoins", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "amountSC", + type: "uint256" + }, + { + internalType: "address", + name: "receiver", + type: "address" + }, + { + internalType: "uint256", + name: "feeUI", + type: "uint256" + }, + { + internalType: "address", + name: "ui", + type: "address" + } + ], + name: "sellStableCoins", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + ], + name: "stableCoin", + outputs: [ + { + internalType: "contract Coin", + name: "", + type: "address" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "thresholdSupplySC", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "treasury", + outputs: [ + { + internalType: "address", + name: "", + type: "address" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "treasuryFee", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "treasuryRevenue", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "treasuryRevenueTarget", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "txLimit", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "scMaxPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_currentPaymentAmount", + type: "uint256" + } + ], + name: "scMinPrice", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "ratioMax", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "ratioMin", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + ], + name: "updateOracleValues", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + } + ]; + var djedTefnutArtifact = { + contractName: contractName$2, + abi: abi$5 + }; + + var contractName$1 = "Coin"; + var abi$4 = [ + { + inputs: [ + { + internalType: "string", + name: "name", + type: "string" + }, + { + internalType: "string", + name: "symbol", + type: "string" + } + ], + stateMutability: "nonpayable", + type: "constructor" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "owner", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "spender", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "value", + type: "uint256" + } + ], + name: "Approval", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: true, + internalType: "address", + name: "from", + type: "address" + }, + { + indexed: true, + internalType: "address", + name: "to", + type: "address" + }, + { + indexed: false, + internalType: "uint256", + name: "value", + type: "uint256" + } + ], + name: "Transfer", + type: "event" + }, + { + inputs: [ + { + internalType: "address", + name: "owner", + type: "address" + }, + { + internalType: "address", + name: "spender", + type: "address" + } + ], + name: "allowance", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "spender", + type: "address" + }, + { + internalType: "uint256", + name: "amount", + type: "uint256" + } + ], + name: "approve", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool" + } + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "account", + type: "address" + } + ], + name: "balanceOf", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "spender", + type: "address" + }, + { + internalType: "uint256", + name: "subtractedValue", + type: "uint256" + } + ], + name: "decreaseAllowance", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool" + } + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "spender", + type: "address" + }, + { + internalType: "uint256", + name: "addedValue", + type: "uint256" + } + ], + name: "increaseAllowance", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool" + } + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + ], name: "name", outputs: [ { @@ -1611,7 +3504,7 @@ ]; var coinArtifact = { contractName: contractName$1, - abi: abi$1 + abi: abi$4 }; //setting up djed @@ -1620,6 +3513,16 @@ return djed; }; + const getDjedIsisContract = (web3, DJED_ADDRESS) => { + const djed = new web3.eth.Contract(djedIsisArtifact.abi, DJED_ADDRESS); + return djed; + }; + + const getDjedTefnutContract = (web3, DJED_ADDRESS) => { + const djed = new web3.eth.Contract(djedTefnutArtifact.abi, DJED_ADDRESS); + return djed; + }; + const getCoinContracts = async (djedContract, web3) => { const [stableCoinAddress, reserveCoinAddress] = await Promise.all([ web3Promise$1(djedContract, "stableCoin"), @@ -1640,6 +3543,16 @@ return { scDecimals, rcDecimals }; }; + const checkIfShu = async (djedContract) => { + try { + // Check if scMaxPrice exists on the contract + await djedContract.methods.scMaxPrice(0).call(); + return true; + } catch (e) { + return false; + } + }; + const getCoinDetails = async ( stableCoin, reserveCoin, @@ -1648,6 +3561,9 @@ rcDecimals ) => { try { + const isShu = await checkIfShu(djed); + const priceMethod = isShu ? "scMaxPrice" : "scPrice"; + const [ [scaledNumberSc, unscaledNumberSc], [scaledPriceSc, unscaledPriceSc], @@ -1657,14 +3573,14 @@ scaledScExchangeRate, ] = await Promise.all([ scaledUnscaledPromise(web3Promise$1(stableCoin, "totalSupply"), scDecimals), - scaledUnscaledPromise(web3Promise$1(djed, "scPrice", 0), BC_DECIMALS), + scaledUnscaledPromise(web3Promise$1(djed, priceMethod, 0), BC_DECIMALS), scaledUnscaledPromise( web3Promise$1(reserveCoin, "totalSupply"), rcDecimals ), scaledUnscaledPromise(web3Promise$1(djed, "R", 0), BC_DECIMALS), scaledPromise(web3Promise$1(djed, "rcBuyingPrice", 0), BC_DECIMALS), - scaledPromise(web3Promise$1(djed, "scPrice", 0), BC_DECIMALS), + scaledPromise(web3Promise$1(djed, priceMethod, 0), BC_DECIMALS), ]); // Define default empty value @@ -1672,6 +3588,8 @@ let scaledSellPriceRc = emptyValue; let unscaledSellPriceRc = emptyValue; let percentReserveRatio = emptyValue; + let percentReserveRatioMin = emptyValue; + let percentReserveRatioMax = emptyValue; // Check total reserve coin supply to calculate sell price if (BigInt(unscaledNumberRc) !== 0n) { @@ -1683,14 +3601,25 @@ // Check total stable coin supply to calculate reserve ratio if (BigInt(unscaledNumberSc) !== 0n) { - percentReserveRatio = await percentScaledPromise( - web3Promise$1(djed, "ratio"), - SCALING_DECIMALS - ); + if (isShu) { + const [ratioMin, ratioMax] = await Promise.all([ + percentScaledPromise(web3Promise$1(djed, "ratioMin"), SCALING_DECIMALS), + percentScaledPromise(web3Promise$1(djed, "ratioMax"), SCALING_DECIMALS) + ]); + percentReserveRatioMin = ratioMin; + percentReserveRatioMax = ratioMax; + percentReserveRatio = `${ratioMin} - ${ratioMax}`; + } else { + percentReserveRatio = await percentScaledPromise( + web3Promise$1(djed, "ratio"), + SCALING_DECIMALS + ); + } } // Return the results return { + isShu, scaledNumberSc, unscaledNumberSc, scaledPriceSc, @@ -1700,6 +3629,8 @@ scaledReserveBc, unscaledReserveBc, percentReserveRatio, + percentReserveRatioMin, + percentReserveRatioMax, scaledBuyPriceRc, scaledSellPriceRc, unscaledSellPriceRc, @@ -1718,12 +3649,22 @@ feeUnscaled, treasuryFee, thresholdSupplySC, + initialTreasuryFee, + treasuryRevenueTarget, + treasuryRevenue, + rcMinPrice, + txLimit, ] = await Promise.all([ web3Promise$1(djed, "reserveRatioMin"), web3Promise$1(djed, "reserveRatioMax"), web3Promise$1(djed, "fee"), percentScaledPromise(web3Promise$1(djed, "treasuryFee"), SCALING_DECIMALS), web3Promise$1(djed, "thresholdSupplySC"), + web3Promise$1(djed, "initialTreasuryFee"), + web3Promise$1(djed, "treasuryRevenueTarget"), + web3Promise$1(djed, "treasuryRevenue"), + web3Promise$1(djed, "rcMinPrice"), + web3Promise$1(djed, "txLimit"), ]); return { @@ -1743,6 +3684,12 @@ feeUnscaled, treasuryFee, thresholdSupplySC, + initialTreasuryFee: percentageScale(initialTreasuryFee, SCALING_DECIMALS, true), + initialTreasuryFeeUnscaled: initialTreasuryFee, + treasuryRevenueTarget, + treasuryRevenue, + rcMinPrice, + txLimit, }; }; @@ -1780,148 +3727,433 @@ }; }; + /** + * Utility to listen for Djed contract events + * @param {Object} djedContract - The Web3 contract instance + * @param {Object} callbacks - Object containing callback functions for different events + * @param {Function} callbacks.onBoughtStableCoins - (eventData) => {} + * @param {Function} callbacks.onSoldStableCoins - (eventData) => {} + * @param {Function} callbacks.onBoughtReserveCoins - (eventData) => {} + * @param {Function} callbacks.onSoldReserveCoins - (eventData) => {} + * @param {Function} callbacks.onSoldBothCoins - (eventData) => {} + * @param {Function} callbacks.onError - (error) => {} + */ + const subscribeToDjedEvents = (djedContract, callbacks) => { + const events = [ + { name: "BoughtStableCoins", cb: callbacks.onBoughtStableCoins }, + { name: "SoldStableCoins", cb: callbacks.onSoldStableCoins }, + { name: "BoughtReserveCoins", cb: callbacks.onBoughtReserveCoins }, + { name: "SoldReserveCoins", cb: callbacks.onSoldReserveCoins }, + { name: "SoldBothCoins", cb: callbacks.onSoldBothCoins }, + ]; + + const subscriptions = []; + + events.forEach((event) => { + if (event.cb) { + const sub = djedContract.events[event.name]({ + fromBlock: "latest", + }) + .on("data", (data) => { + event.cb(data.returnValues); + }) + .on("error", (err) => { + if (callbacks.onError) callbacks.onError(err); + else console.error(`Error in ${event.name} subscription:`, err); + }); + subscriptions.push(sub); + } + }); + + return { + unsubscribe: () => { + subscriptions.forEach((sub) => { + if (sub.unsubscribe) sub.unsubscribe(); + }); + }, + }; + }; + + /** + * Utility to fetch past events from the Djed contract + * @param {Object} djedContract - The Web3 contract instance + * @param {string} eventName - Name of the event + * @param {Object} filter - Web3 filter object (e.g., { buyer: '0x...' }) + * @param {number|string} fromBlock - Starting block + * @returns {Promise} - Array of past events + */ + const getPastDjedEvents = async ( + djedContract, + eventName, + filter = {}, + fromBlock = 0 + ) => { + try { + return await djedContract.getPastEvents(eventName, { + filter, + fromBlock, + toBlock: "latest", + }); + } catch (error) { + console.error(`Error fetching past events for ${eventName}:`, error); + throw error; + } + }; + + const approveTx = (tokenContract, owner, spender, amount) => { + const data = tokenContract.methods.approve(spender, amount).encodeABI(); + return buildTx(owner, tokenContract.options.address, 0, data); + }; + + const checkAllowance = async (tokenContract, owner, spender) => { + return await tokenContract.methods.allowance(owner, spender).call(); + }; + var contractName = "Oracle"; - var abi = [ + var abi$3 = [ + { + inputs: [ + { + internalType: "address", + name: "_owner", + type: "address" + }, + { + internalType: "string", + name: "_description", + type: "string" + }, + { + internalType: "string", + name: "_termsOfService", + type: "string" + } + ], + stateMutability: "nonpayable", + type: "constructor" + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "uint256", + name: "data", + type: "uint256" + } + ], + name: "DataWritten", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "address", + name: "a", + type: "address" + }, + { + indexed: false, + internalType: "address", + name: "opposer", + type: "address" + } + ], + name: "OppositionAdded", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "address", + name: "a", + type: "address" + }, + { + indexed: false, + internalType: "address", + name: "opposer", + type: "address" + } + ], + name: "OppositionRemoved", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "address", + name: "a", + type: "address" + } + ], + name: "OwnerAdded", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "address", + name: "a", + type: "address" + } + ], + name: "OwnerRemoved", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "address", + name: "a", + type: "address" + }, + { + indexed: false, + internalType: "address", + name: "supporter", + type: "address" + } + ], + name: "SupportAdded", + type: "event" + }, + { + anonymous: false, + inputs: [ + { + indexed: false, + internalType: "address", + name: "a", + type: "address" + }, + { + indexed: false, + internalType: "address", + name: "supporter", + type: "address" + } + ], + name: "SupportRemoved", + type: "event" + }, + { + inputs: [ + ], + name: "acceptTermsOfService", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "", + type: "address" + } + ], + name: "acceptedTermsOfService", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool" + } + ], + stateMutability: "view", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "a", + type: "address" + } + ], + name: "add", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, { inputs: [ - { - internalType: "address", - name: "_owner", - type: "address" - }, - { - internalType: "string", - name: "_description", - type: "string" - }, + ], + name: "description", + outputs: [ { internalType: "string", - name: "_termsOfService", + name: "", type: "string" } ], - stateMutability: "nonpayable", - type: "constructor" + stateMutability: "view", + type: "function" }, { - anonymous: false, inputs: [ + ], + name: "numOwners", + outputs: [ { - indexed: false, internalType: "uint256", - name: "data", + name: "", type: "uint256" } ], - name: "DataWritten", - type: "event" + stateMutability: "view", + type: "function" }, { - anonymous: false, inputs: [ { - indexed: false, internalType: "address", name: "a", type: "address" + } + ], + name: "oppose", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "address", + name: "", + type: "address" }, { - indexed: false, internalType: "address", - name: "opposer", + name: "", type: "address" } ], - name: "OppositionAdded", - type: "event" + name: "opposers", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool" + } + ], + stateMutability: "view", + type: "function" }, { - anonymous: false, inputs: [ { - indexed: false, internalType: "address", - name: "a", + name: "", type: "address" }, { - indexed: false, + internalType: "uint256", + name: "", + type: "uint256" + } + ], + name: "opposing", + outputs: [ + { internalType: "address", - name: "opposer", + name: "", type: "address" } ], - name: "OppositionRemoved", - type: "event" + stateMutability: "view", + type: "function" }, { - anonymous: false, inputs: [ { - indexed: false, internalType: "address", - name: "a", + name: "", type: "address" } ], - name: "OwnerAdded", - type: "event" + name: "oppositionCounter", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ], + stateMutability: "view", + type: "function" }, { - anonymous: false, inputs: [ { - indexed: false, internalType: "address", - name: "a", + name: "", type: "address" } ], - name: "OwnerRemoved", - type: "event" + name: "owner", + outputs: [ + { + internalType: "bool", + name: "", + type: "bool" + } + ], + stateMutability: "view", + type: "function" }, { - anonymous: false, inputs: [ + ], + name: "readData", + outputs: [ { - indexed: false, - internalType: "address", - name: "a", - type: "address" - }, - { - indexed: false, - internalType: "address", - name: "supporter", - type: "address" + internalType: "uint256", + name: "", + type: "uint256" } ], - name: "SupportAdded", - type: "event" + stateMutability: "view", + type: "function" }, { - anonymous: false, inputs: [ { - indexed: false, internalType: "address", name: "a", type: "address" - }, - { - indexed: false, - internalType: "address", - name: "supporter", - type: "address" } ], - name: "SupportRemoved", - type: "event" + name: "remove", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" }, { inputs: [ + { + internalType: "address", + name: "a", + type: "address" + } ], - name: "acceptTermsOfService", + name: "support", outputs: [ ], stateMutability: "nonpayable", @@ -1935,12 +4167,12 @@ type: "address" } ], - name: "acceptedTermsOfService", + name: "supportCounter", outputs: [ { - internalType: "bool", + internalType: "uint256", name: "", - type: "bool" + type: "uint256" } ], stateMutability: "view", @@ -1950,25 +4182,45 @@ inputs: [ { internalType: "address", - name: "a", + name: "", + type: "address" + }, + { + internalType: "address", + name: "", type: "address" } ], - name: "add", + name: "supporters", outputs: [ + { + internalType: "bool", + name: "", + type: "bool" + } ], - stateMutability: "nonpayable", + stateMutability: "view", type: "function" }, { inputs: [ + { + internalType: "address", + name: "", + type: "address" + }, + { + internalType: "uint256", + name: "", + type: "uint256" + } ], - name: "description", + name: "supporting", outputs: [ { - internalType: "string", + internalType: "address", name: "", - type: "string" + type: "address" } ], stateMutability: "view", @@ -1977,12 +4229,12 @@ { inputs: [ ], - name: "numOwners", + name: "termsOfService", outputs: [ { - internalType: "uint256", + internalType: "string", name: "", - type: "uint256" + type: "string" } ], stateMutability: "view", @@ -1996,7 +4248,7 @@ type: "address" } ], - name: "oppose", + name: "unoppose", outputs: [ ], stateMutability: "nonpayable", @@ -2006,257 +4258,852 @@ inputs: [ { internalType: "address", - name: "", + name: "a", type: "address" + } + ], + name: "unsupport", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + }, + { + inputs: [ + { + internalType: "uint256", + name: "_data", + type: "uint256" + } + ], + name: "writeData", + outputs: [ + ], + stateMutability: "nonpayable", + type: "function" + } + ]; + var oracleArtifact = { + contractName: contractName, + abi: abi$3 + }; + + var abi$2 = [ + { + type: "constructor", + inputs: [ + { + name: "_ref", + type: "address", + internalType: "contract IStdReference" }, { - internalType: "address", - name: "", - type: "address" + name: "_decimals", + type: "uint8", + internalType: "uint8" + }, + { + name: "_hebeSwapDecimals", + type: "uint8", + internalType: "uint8" + }, + { + name: "_baseToken", + type: "string", + internalType: "string" + }, + { + name: "_quoteToken", + type: "string", + internalType: "string" } ], - name: "opposers", + stateMutability: "nonpayable" + }, + { + type: "function", + name: "acceptTermsOfService", + inputs: [ + ], + outputs: [ + ], + stateMutability: "nonpayable" + }, + { + type: "function", + name: "baseToken", + inputs: [ + ], outputs: [ { - internalType: "bool", name: "", - type: "bool" + type: "string", + internalType: "string" } ], - stateMutability: "view", - type: "function" + stateMutability: "view" }, { + type: "function", + name: "quoteToken", inputs: [ - { - internalType: "address", - name: "", - type: "address" - }, - { - internalType: "uint256", - name: "", - type: "uint256" - } ], - name: "opposing", outputs: [ { - internalType: "address", name: "", - type: "address" + type: "string", + internalType: "string" } ], - stateMutability: "view", - type: "function" + stateMutability: "view" }, { + type: "function", + name: "readData", inputs: [ - { - internalType: "address", - name: "", - type: "address" - } ], - name: "oppositionCounter", outputs: [ { - internalType: "uint256", name: "", - type: "uint256" + type: "uint256", + internalType: "uint256" } ], - stateMutability: "view", - type: "function" + stateMutability: "view" }, { + type: "function", + name: "ref", inputs: [ - { - internalType: "address", - name: "", - type: "address" - } ], - name: "owner", outputs: [ { - internalType: "bool", name: "", - type: "bool" + type: "address", + internalType: "contract IStdReference" } ], - stateMutability: "view", - type: "function" + stateMutability: "view" }, { + type: "function", + name: "scalingFactor", inputs: [ ], - name: "readData", outputs: [ { - internalType: "uint256", name: "", - type: "uint256" + type: "uint256", + internalType: "uint256" } ], - stateMutability: "view", - type: "function" + stateMutability: "view" + } + ]; + var bytecode$2 = { + object: "0x60c060405234620000db5762000b08803803806200001d81620000f7565b928339810160a082820312620000db578151906001600160a01b0382168203620000db576200004f602084016200012c565b6200005d604085016200012c565b60608501516001600160401b039591929190868111620000db5784620000859183016200013b565b936080820151968711620000db57620000ab96620000a492016200013b565b93620003d9565b6040516105d1908162000537823960805181818161037201526103f7015260a05181818161043501526104fe0152f35b600080fd5b50634e487b7160e01b600052604160045260246000fd5b6040519190601f01601f191682016001600160401b038111838210176200011d57604052565b62000127620000e0565b604052565b519060ff82168203620000db57565b81601f82011215620000db578051906001600160401b038211620001bf575b60209062000171601f8401601f19168301620000f7565b93838552828483010111620000db5782906000905b83838310620001a6575050116200019c57505090565b6000918301015290565b8193508281939201015182828801015201839162000186565b620001c9620000e0565b6200015a565b50634e487b7160e01b600052601160045260246000fd5b90600182811c9216801562000218575b60208310146200020257565b634e487b7160e01b600052602260045260246000fd5b91607f1691620001f6565b601f811162000230575050565b60009081805260208220906020601f850160051c8301941062000270575b601f0160051c01915b8281106200026457505050565b81815560010162000257565b90925082906200024e565b90601f821162000289575050565b60019160009083825260208220906020601f850160051c83019410620002cc575b601f0160051c01915b828110620002c15750505050565b8181558301620002b3565b9092508290620002aa565b80519091906001600160401b038111620003c9575b6001906200030681620003008454620001e6565b6200027b565b602080601f83116001146200034457508192939460009262000338575b5050600019600383901b1c191690821b179055565b01519050388062000323565b6001600052601f198316959091907fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6926000905b888210620003b1575050838596971062000397575b505050811b019055565b015160001960f88460031b161c191690553880806200038d565b80878596829496860151815501950193019062000378565b620003d3620000e0565b620002ec565b6080529193929160ff91821690821681811062000526575b0316604d811162000516575b600a0a60a05282516001600160401b03811162000506575b6000906200042f81620004298454620001e6565b62000223565b602080601f8311600114620004775750819062000469959684926200046b575b50508160011b916000199060031b1c1916179055620002d7565b565b0151905038806200044f565b60008052601f198316967f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563929185905b898210620004ed5750509083929160019462000469989910620004d3575b505050811b019055620002d7565b015160001960f88460031b161c19169055388080620004c5565b80600185968294968601518155019501930190620004a7565b62000510620000e0565b62000415565b62000520620001cf565b620003fd565b62000530620001cf565b620003f156fe60806040526004361015610013575b600080fd5b6000803560e01c908163217a4b701461008e5750806321a78f6814610085578063bef55ef31461007c578063c55dae6314610073578063dddd9e961461006a5763ed3437f81461006257600080fd5b61000e6104e5565b5061000e6104d1565b5061000e6104a5565b5061000e6103a1565b5061000e61035b565b346100b957806003193601126100b9576100b56100a961024e565b60405191829182610304565b0390f35b80fd5b90600182811c921680156100ec575b60208310146100d657565b634e487b7160e01b600052602260045260246000fd5b91607f16916100cb565b9060009160005490610107826100bc565b8082529160019081811690811561017d575060011461012557505050565b91929350600080527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563916000925b84841061016557505060209250010190565b80546020858501810191909152909301928101610153565b60ff191660208401525050604001925050565b906000916001908154916101a3836100bc565b8083529281811690811561017d57506001146101be57505050565b80929394506000527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6916000925b8484106101fe57505060209250010190565b805460208585018101919091529093019281016101ec565b90601f8019910116810190811067ffffffffffffffff82111761023857604052565b634e487b7160e01b600052604160045260246000fd5b604051600081600191825492610263846100bc565b808452938181169081156102e7575060011461028a575b5061028792500382610216565b90565b600081815291507fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf65b8483106102cc575061028793505081016020013861027a565b819350908160209254838589010152019101909184926102b3565b94505050505060ff1916602082015261028781604081013861027a565b919091602080825283519081818401526000945b828610610345575050806040939411610338575b601f01601f1916010190565b600083828401015261032c565b8581018201518487016040015294810194610318565b503461000e57600036600319011261000e576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b503461000e5760031960003682011261000e5761045a6103f360606100b5936040518093819263195556f360e21b8352604060048401526103e4604484016100f6565b90838203016024840152610190565b03817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610498575b60009161046a575b50517f000000000000000000000000000000000000000000000000000000000000000090610572565b6040519081529081906020820190565b61048b915060603d8111610491575b6104838183610216565b810190610521565b38610431565b503d610479565b6104a0610565565b610429565b503461000e57600036600319011261000e576100b56040516100a9816104ca816100f6565b0382610216565b503461000e57600036600319011261000e57005b503461000e57600036600319011261000e5760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b9081606091031261000e5760405190606082019082821067ffffffffffffffff83111761023857604091825280518352602081015160208401520151604082015290565b506040513d6000823e3d90fd5b8060001904821181151516610585570290565b634e487b7160e01b600052601160045260246000fdfea264697066735822122053cfb7b37092c28d461cf6387ad085646c5cf4ccd06822d58ce0f7819d82b38b64736f6c634300080d0033", + sourceMap: "120:827:2:-:0;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;-1:-1:-1;;;;;120:827:2;;;;;;;;;;;:::i;:::-;;;;;;:::i;:::-;;;;;-1:-1:-1;;;;;120:827:2;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;:::i;:::-;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;120:827:2;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;120:827:2;;;-1:-1:-1;;;;;120:827:2;;;;;;;;;;:::o;:::-;;;:::i;:::-;;;:::o;:::-;;;;;;;;;;:::o;:::-;;;;;;;;;;;;-1:-1:-1;;;;;120:827:2;;;;;;;;;;;-1:-1:-1;;120:827:2;;;;:::i;:::-;;;;;;;;;;;;;;;-1:-1:-1;120:827:2;;;;;;;;;;;;;;;;:::o;:::-;-1:-1:-1;120:827:2;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;578:22;120:827;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;-1:-1:-1;120:827:2;;;;;;;;;;;;;:::o;:::-;610:24;-1:-1:-1;;120:827:2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;-1:-1:-1;120:827:2;;;;;;;;;;-1:-1:-1;;;;;120:827:2;;;;;;;;;;;;;:::i;:::-;;:::i;:::-;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;120:827:2;;;;;;;;;;;;;:::o;:::-;;;;-1:-1:-1;120:827:2;;;;;610:24;120:827;;-1:-1:-1;;120:827:2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;305:336;488:10;;305:336;;;;120:827;;;;;;;;;;;;305:336;120:827;;;;;;;305:336;120:827;;508:60;;120:827;;-1:-1:-1;;;;;120:827:2;;;;305:336;-1:-1:-1;120:827:2;;;;;;;:::i;:::-;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;305:336::o;120:827::-;;;;-1:-1:-1;120:827:2;;;;;578:22;120:827;;-1:-1:-1;;120:827:2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;:::i;:::-;;;;;;:::i;:::-;;", + linkReferences: { + } + }; + var deployedBytecode$2 = { + object: "0x60806040526004361015610013575b600080fd5b6000803560e01c908163217a4b701461008e5750806321a78f6814610085578063bef55ef31461007c578063c55dae6314610073578063dddd9e961461006a5763ed3437f81461006257600080fd5b61000e6104e5565b5061000e6104d1565b5061000e6104a5565b5061000e6103a1565b5061000e61035b565b346100b957806003193601126100b9576100b56100a961024e565b60405191829182610304565b0390f35b80fd5b90600182811c921680156100ec575b60208310146100d657565b634e487b7160e01b600052602260045260246000fd5b91607f16916100cb565b9060009160005490610107826100bc565b8082529160019081811690811561017d575060011461012557505050565b91929350600080527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563916000925b84841061016557505060209250010190565b80546020858501810191909152909301928101610153565b60ff191660208401525050604001925050565b906000916001908154916101a3836100bc565b8083529281811690811561017d57506001146101be57505050565b80929394506000527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6916000925b8484106101fe57505060209250010190565b805460208585018101919091529093019281016101ec565b90601f8019910116810190811067ffffffffffffffff82111761023857604052565b634e487b7160e01b600052604160045260246000fd5b604051600081600191825492610263846100bc565b808452938181169081156102e7575060011461028a575b5061028792500382610216565b90565b600081815291507fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf65b8483106102cc575061028793505081016020013861027a565b819350908160209254838589010152019101909184926102b3565b94505050505060ff1916602082015261028781604081013861027a565b919091602080825283519081818401526000945b828610610345575050806040939411610338575b601f01601f1916010190565b600083828401015261032c565b8581018201518487016040015294810194610318565b503461000e57600036600319011261000e576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b503461000e5760031960003682011261000e5761045a6103f360606100b5936040518093819263195556f360e21b8352604060048401526103e4604484016100f6565b90838203016024840152610190565b03817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610498575b60009161046a575b50517f000000000000000000000000000000000000000000000000000000000000000090610572565b6040519081529081906020820190565b61048b915060603d8111610491575b6104838183610216565b810190610521565b38610431565b503d610479565b6104a0610565565b610429565b503461000e57600036600319011261000e576100b56040516100a9816104ca816100f6565b0382610216565b503461000e57600036600319011261000e57005b503461000e57600036600319011261000e5760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b9081606091031261000e5760405190606082019082821067ffffffffffffffff83111761023857604091825280518352602081015160208401520151604082015290565b506040513d6000823e3d90fd5b8060001904821181151516610585570290565b634e487b7160e01b600052601160045260246000fdfea264697066735822122053cfb7b37092c28d461cf6387ad085646c5cf4ccd06822d58ce0f7819d82b38b64736f6c634300080d0033", + sourceMap: "120:827:2:-:0;;;;;;;;;-1:-1:-1;120:827:2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;:::i;:::-;;;;:::i;:::-;;;;:::i;:::-;;;;;;;;;;;;;274:24;;:::i;:::-;120:827;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;120:827:2;;;;;-1:-1:-1;;120:827:2;;;-1:-1:-1;;120:827:2:o;:::-;;;;857:10;120:827;;;;;;;:::i;:::-;;;;;;;;;857:10;;;;120:827;;;;;;;;:::o;:::-;;;;;;-1:-1:-1;120:827:2;;;-1:-1:-1;120:827:2;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;-1:-1:-1;274:24:2;;120:827;;;;;;;:::i;:::-;;;;;;;;;274:24;;;;120:827;;;;;;;;;;;;;:::i;:::-;;:::o;:::-;-1:-1:-1;120:827:2;;;-1:-1:-1;;120:827:2;;;;;;;-1:-1:-1;120:827:2;;-1:-1:-1;;120:827:2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;120:827:2;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;120:827:2;;;;;;161:34;-1:-1:-1;;;;;120:827:2;;;;;;;;;;;-1:-1:-1;;120:827:2;;;;;;;895:42;120:827;800:77;120:827;;;;;;;;;;;800:77;;120:827;;800:77;;120:827;;;;;;:::i;:::-;;;;;;;;;;;:::i;:::-;800:77;120:827;800:3;-1:-1:-1;;;;;120:827:2;800:77;;;;;;;120:827;;800:77;;;120:827;;;924:13;895:42;;:::i;:::-;120:827;;;;;;;;;;;;;800:77;;;;;;;;;;;;;;;:::i;:::-;;;;;:::i;:::-;;;;;;;;;;;;:::i;:::-;;;120:827;;;;;;;-1:-1:-1;;120:827:2;;;;;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;;;;-1:-1:-1;;120:827:2;;;;;;;;;;;;-1:-1:-1;;120:827:2;;;;;;;201:38;120:827;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;", + linkReferences: { }, - { - inputs: [ + immutableReferences: { + "131": [ { - internalType: "address", - name: "a", - type: "address" + start: 882, + length: 32 + }, + { + start: 1015, + length: 32 } ], - name: "remove", - outputs: [ + "133": [ + { + start: 1077, + length: 32 + }, + { + start: 1278, + length: 32 + } + ] + } + }; + var methodIdentifiers$2 = { + "acceptTermsOfService()": "dddd9e96", + "baseToken()": "c55dae63", + "quoteToken()": "217a4b70", + "readData()": "bef55ef3", + "ref()": "21a78f68", + "scalingFactor()": "ed3437f8" + }; + var rawMetadata$2 = "{\"compiler\":{\"version\":\"0.8.13+commit.abaa5c0e\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"contract IStdReference\",\"name\":\"_ref\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"_decimals\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"_hebeSwapDecimals\",\"type\":\"uint8\"},{\"internalType\":\"string\",\"name\":\"_baseToken\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"_quoteToken\",\"type\":\"string\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"acceptTermsOfService\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"baseToken\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"quoteToken\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"readData\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"ref\",\"outputs\":[{\"internalType\":\"contract IStdReference\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"scalingFactor\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/HebeSwapOracle.sol\":\"HebeSwapOracle\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[\":@api3dao/=lib/contracts/\",\":@chainlink/contracts/=node_modules/@chainlink/contracts/\",\":@eth-optimism/=node_modules/@eth-optimism/\",\":@hebeswap/=lib/hebeswap-contract/\",\":@openzeppelin/=lib/openzeppelin-contracts/\",\":ds-test/=lib/forge-std/lib/ds-test/src/\",\":forge-std/=lib/forge-std/src/\",\":hebeswap-contract/=lib/hebeswap-contract/\",\":openzeppelin-contracts/=lib/openzeppelin-contracts/\",\":solmate/=lib/solmate/src/\"],\"viaIR\":true},\"sources\":{\"lib/hebeswap-contract/IStdReference.sol\":{\"keccak256\":\"0x805354452e33be1dfd58447a237b6bd506287bd30337543cc1e07e05601e4e18\",\"license\":\"Apache-2.0\",\"urls\":[\"bzz-raw://14662cd18e5e122d927e027d8f2ace81d298f5e9b26b84e07a42cd587711a271\",\"dweb:/ipfs/QmWRwfUpiGXspRSJboXBGXmMzzYbDkT2Hs276rRehbtAkT\"]},\"src/HebeSwapOracle.sol\":{\"keccak256\":\"0x24e9a24e8105104d57c6ad72be5bbfa8c7b9cdb77a27102453bd632aa79fbbea\",\"license\":\"AEL\",\"urls\":[\"bzz-raw://236777fe9d91c7e587a092ce6f2ffcdcadea603211a9327a854d81630a9ee824\",\"dweb:/ipfs/QmQrhn7fNXb2gHDk5YqNv3viTv24RgHqV9EsKWe9pD8kB7\"]},\"src/IOracle.sol\":{\"keccak256\":\"0xbdb82189368be9100ec49015ca5838207a3bc5bfec11543d0aede20811cb07ad\",\"license\":\"AEL\",\"urls\":[\"bzz-raw://d6f64b8238eaa188a9b9d7acac753ba0bfccc770b458be512c37c47bc8cafe4c\",\"dweb:/ipfs/QmWB2nD9chE3EAKYa4joucZUsFstZNJDjRoDbrdXEKkYk1\"]}},\"version\":1}"; + var metadata$2 = { + compiler: { + version: "0.8.13+commit.abaa5c0e" + }, + language: "Solidity", + output: { + abi: [ + { + inputs: [ + { + internalType: "contract IStdReference", + name: "_ref", + type: "address" + }, + { + internalType: "uint8", + name: "_decimals", + type: "uint8" + }, + { + internalType: "uint8", + name: "_hebeSwapDecimals", + type: "uint8" + }, + { + internalType: "string", + name: "_baseToken", + type: "string" + }, + { + internalType: "string", + name: "_quoteToken", + type: "string" + } + ], + stateMutability: "nonpayable", + type: "constructor" + }, + { + inputs: [ + ], + stateMutability: "nonpayable", + type: "function", + name: "acceptTermsOfService" + }, + { + inputs: [ + ], + stateMutability: "view", + type: "function", + name: "baseToken", + outputs: [ + { + internalType: "string", + name: "", + type: "string" + } + ] + }, + { + inputs: [ + ], + stateMutability: "view", + type: "function", + name: "quoteToken", + outputs: [ + { + internalType: "string", + name: "", + type: "string" + } + ] + }, + { + inputs: [ + ], + stateMutability: "view", + type: "function", + name: "readData", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ] + }, + { + inputs: [ + ], + stateMutability: "view", + type: "function", + name: "ref", + outputs: [ + { + internalType: "contract IStdReference", + name: "", + type: "address" + } + ] + }, + { + inputs: [ + ], + stateMutability: "view", + type: "function", + name: "scalingFactor", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ] + } ], - stateMutability: "nonpayable", - type: "function" + devdoc: { + kind: "dev", + methods: { + }, + version: 1 + }, + userdoc: { + kind: "user", + methods: { + }, + version: 1 + } + }, + settings: { + remappings: [ + "@api3dao/=lib/contracts/", + "@chainlink/contracts/=node_modules/@chainlink/contracts/", + "@eth-optimism/=node_modules/@eth-optimism/", + "@hebeswap/=lib/hebeswap-contract/", + "@openzeppelin/=lib/openzeppelin-contracts/", + "ds-test/=lib/forge-std/lib/ds-test/src/", + "forge-std/=lib/forge-std/src/", + "hebeswap-contract/=lib/hebeswap-contract/", + "openzeppelin-contracts/=lib/openzeppelin-contracts/", + "solmate/=lib/solmate/src/" + ], + optimizer: { + enabled: true, + runs: 200 + }, + metadata: { + bytecodeHash: "ipfs" + }, + compilationTarget: { + "src/HebeSwapOracle.sol": "HebeSwapOracle" + }, + evmVersion: "london", + libraries: { + }, + viaIR: true }, + sources: { + "lib/hebeswap-contract/IStdReference.sol": { + keccak256: "0x805354452e33be1dfd58447a237b6bd506287bd30337543cc1e07e05601e4e18", + urls: [ + "bzz-raw://14662cd18e5e122d927e027d8f2ace81d298f5e9b26b84e07a42cd587711a271", + "dweb:/ipfs/QmWRwfUpiGXspRSJboXBGXmMzzYbDkT2Hs276rRehbtAkT" + ], + license: "Apache-2.0" + }, + "src/HebeSwapOracle.sol": { + keccak256: "0x24e9a24e8105104d57c6ad72be5bbfa8c7b9cdb77a27102453bd632aa79fbbea", + urls: [ + "bzz-raw://236777fe9d91c7e587a092ce6f2ffcdcadea603211a9327a854d81630a9ee824", + "dweb:/ipfs/QmQrhn7fNXb2gHDk5YqNv3viTv24RgHqV9EsKWe9pD8kB7" + ], + license: "AEL" + }, + "src/IOracle.sol": { + keccak256: "0xbdb82189368be9100ec49015ca5838207a3bc5bfec11543d0aede20811cb07ad", + urls: [ + "bzz-raw://d6f64b8238eaa188a9b9d7acac753ba0bfccc770b458be512c37c47bc8cafe4c", + "dweb:/ipfs/QmWB2nD9chE3EAKYa4joucZUsFstZNJDjRoDbrdXEKkYk1" + ], + license: "AEL" + } + }, + version: 1 + }; + var id$2 = 2; + var hebeSwapOracleArtifact = { + abi: abi$2, + bytecode: bytecode$2, + deployedBytecode: deployedBytecode$2, + methodIdentifiers: methodIdentifiers$2, + rawMetadata: rawMetadata$2, + metadata: metadata$2, + id: id$2 + }; + + var abi$1 = [ { + type: "constructor", inputs: [ { - internalType: "address", - name: "a", - type: "address" + name: "_dataFeedAddress", + type: "address", + internalType: "address" + }, + { + name: "_decimals", + type: "uint256", + internalType: "uint256" } ], - name: "support", + stateMutability: "nonpayable" + }, + { + type: "function", + name: "acceptTermsOfService", + inputs: [ + ], outputs: [ ], - stateMutability: "nonpayable", - type: "function" + stateMutability: "nonpayable" }, { + type: "function", + name: "readData", inputs: [ - { - internalType: "address", - name: "", - type: "address" - } ], - name: "supportCounter", outputs: [ { - internalType: "uint256", name: "", - type: "uint256" + type: "uint256", + internalType: "uint256" } ], - stateMutability: "view", - type: "function" + stateMutability: "view" }, { + type: "function", + name: "scalingFactor", inputs: [ + ], + outputs: [ { - internalType: "address", name: "", - type: "address" + type: "uint256", + internalType: "uint256" + } + ], + stateMutability: "view" + } + ]; + var bytecode$1 = { + object: "0x60a0806040523461010057604081610333803803809161001f8285610117565b8339810103126101005780516001600160a01b0381169190829003610100576020908101515f80546001600160a01b0319168417905560405163313ce56760e01b81529092909190829060049082905afa801561010c575f906100cb575b60ff9150169081039081116100b757604d81116100b757600a0a6080526040516101e4908161014f82396080518181816054015260cf0152f35b634e487b7160e01b5f52601160045260245ffd5b506020813d602011610104575b816100e560209383610117565b81010312610100575160ff811681036101005760ff9061007d565b5f80fd5b3d91506100d8565b6040513d5f823e3d90fd5b601f909101601f19168101906001600160401b0382119082101761013a57604052565b634e487b7160e01b5f52604160045260245ffdfe6080806040526004361015610012575f80fd5b5f3560e01c908163bef55ef31461008d57508063dddd9e961461007b5763ed3437f81461003d575f80fd5b34610077575f3660031901126100775760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b5f80fd5b34610077575f36600319011261007757005b34610077575f366003190112610077575f54633fabe5a360e21b825260a090829060049082906001600160a01b03165afa90811561018c575f91610115575b507f00000000000000000000000000000000000000000000000000000000000000009081156101015760209160405191048152f35b634e487b7160e01b5f52601260045260245ffd5b905060a03d60a011610185575b601f8101601f1916820167ffffffffffffffff8111838210176101715760a0918391604052810103126100775761015881610197565b5061016a608060208301519201610197565b50816100cc565b634e487b7160e01b5f52604160045260245ffd5b503d610122565b6040513d5f823e3d90fd5b519069ffffffffffffffffffff821682036100775756fea26469706673582212209673ddeb55b798f5094586c6147a71d254ed39e9b38245e74cfdcd015b47b0cf64736f6c63430008210033", + sourceMap: "159:564:26:-:0;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;-1:-1:-1;;;;;159:564:26;;;;;;;;;;;;;;-1:-1:-1;159:564:26;;-1:-1:-1;;;;;;159:564:26;;;;;;;-1:-1:-1;;;447:19:26;;159:564;;;;;;;447:19;;159:564;;447:19;;;;;;-1:-1:-1;447:19:26;;;-1:-1:-1;159:564:26;;;;;;;;;;;;;;;;;;;418:62;;159:564;;;;;;;;418:62;159:564;;;;;;;;;;;;;;;-1:-1:-1;159:564:26;;447:19;159:564;;-1:-1:-1;159:564:26;447:19;;159:564;447:19;;159:564;447:19;;;;;;159:564;447:19;;;:::i;:::-;;;159:564;;;;;;;;;;;;;447:19;;;159:564;-1:-1:-1;159:564:26;;447:19;;;-1:-1:-1;447:19:26;;;159:564;;;-1:-1:-1;159:564:26;;;;;;;;;;-1:-1:-1;;159:564:26;;;;-1:-1:-1;;;;;159:564:26;;;;;;;;;;:::o;:::-;;;;-1:-1:-1;159:564:26;;;;;-1:-1:-1;159:564:26", + linkReferences: { + } + }; + var deployedBytecode$1 = { + object: "0x6080806040526004361015610012575f80fd5b5f3560e01c908163bef55ef31461008d57508063dddd9e961461007b5763ed3437f81461003d575f80fd5b34610077575f3660031901126100775760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b5f80fd5b34610077575f36600319011261007757005b34610077575f366003190112610077575f54633fabe5a360e21b825260a090829060049082906001600160a01b03165afa90811561018c575f91610115575b507f00000000000000000000000000000000000000000000000000000000000000009081156101015760209160405191048152f35b634e487b7160e01b5f52601260045260245ffd5b905060a03d60a011610185575b601f8101601f1916820167ffffffffffffffff8111838210176101715760a0918391604052810103126100775761015881610197565b5061016a608060208301519201610197565b50816100cc565b634e487b7160e01b5f52604160045260245ffd5b503d610122565b6040513d5f823e3d90fd5b519069ffffffffffffffffffff821682036100775756fea26469706673582212209673ddeb55b798f5094586c6147a71d254ed39e9b38245e74cfdcd015b47b0cf64736f6c63430008210033", + sourceMap: "159:564:26:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;159:564:26;;;;;;;246:38;159:564;;;;;;;;;;;;;-1:-1:-1;;159:564:26;;;;;;;;;;;-1:-1:-1;;159:564:26;;;;;;-1:-1:-1;;;630:26:26;;;;159:564;;;;;;-1:-1:-1;;;;;159:564:26;630:26;;;;;;;159:564;630:26;;;159:564;700:13;;159:564;;;;;;;;;;;;;;;;;;;;;;;;;;630:26;;;;;;;;;;159:564;;;-1:-1:-1;;159:564:26;;;;;;;;;;;;630:26;159:564;;;;;630:26;;159:564;;;;;;;:::i;:::-;;;;;;;;;;;:::i;:::-;;630:26;;;159:564;;;;;;;;;;;;630:26;;;;;;159:564;;;;;;;;;;;;;;;;;;;:::o", + linkReferences: { + }, + immutableReferences: { + "45104": [ + { + start: 84, + length: 32 }, { - internalType: "address", - name: "", - type: "address" + start: 207, + length: 32 } - ], - name: "supporters", - outputs: [ + ] + } + }; + var methodIdentifiers$1 = { + "acceptTermsOfService()": "dddd9e96", + "readData()": "bef55ef3", + "scalingFactor()": "ed3437f8" + }; + var rawMetadata$1 = "{\"compiler\":{\"version\":\"0.8.33+commit.64118f21\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_dataFeedAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_decimals\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"acceptTermsOfService\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"readData\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"scalingFactor\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/ChainlinkOracle.sol\":\"ChainlinkOracle\"},\"evmVersion\":\"prague\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[\":@api3dao/=lib/contracts/\",\":@chainlink/contracts/=node_modules/@chainlink/contracts/\",\":@eth-optimism/=node_modules/@eth-optimism/\",\":@hebeswap/=lib/hebeswap-contract/\",\":@openzeppelin/=lib/openzeppelin-contracts/\",\":ds-test/=lib/forge-std/lib/ds-test/src/\",\":forge-std/=lib/forge-std/src/\",\":hebeswap-contract/=lib/hebeswap-contract/\",\":openzeppelin-contracts/=lib/openzeppelin-contracts/\",\":solmate/=lib/solmate/src/\"],\"viaIR\":true},\"sources\":{\"node_modules/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol\":{\"keccak256\":\"0x6e6e4b0835904509406b070ee173b5bc8f677c19421b76be38aea3b1b3d30846\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://b3beaa37ee61e4ab615e250fbf01601ae481de843fd0ef55e6b44fd9d5fff8a7\",\"dweb:/ipfs/QmeZUVwd26LzK4Mfp8Zba5JbQNkZFfTzFu1A6FVMMZDg9c\"]},\"src/ChainlinkOracle.sol\":{\"keccak256\":\"0xd3a6904bd77d5ee4219b60b519e323268ac4347db771a43bea2c4e2c58b418ad\",\"license\":\"AEL\",\"urls\":[\"bzz-raw://574ddf2d50bffc03e3457150f00a89105882ec86003405011bca28c76f87e635\",\"dweb:/ipfs/QmXBDr2GGd7nnmaC3tbGPm6ASb2ebuqqds1v3rKxD5aDjw\"]},\"src/IOracle.sol\":{\"keccak256\":\"0xbdb82189368be9100ec49015ca5838207a3bc5bfec11543d0aede20811cb07ad\",\"license\":\"AEL\",\"urls\":[\"bzz-raw://d6f64b8238eaa188a9b9d7acac753ba0bfccc770b458be512c37c47bc8cafe4c\",\"dweb:/ipfs/QmWB2nD9chE3EAKYa4joucZUsFstZNJDjRoDbrdXEKkYk1\"]}},\"version\":1}"; + var metadata$1 = { + compiler: { + version: "0.8.33+commit.64118f21" + }, + language: "Solidity", + output: { + abi: [ + { + inputs: [ + { + internalType: "address", + name: "_dataFeedAddress", + type: "address" + }, + { + internalType: "uint256", + name: "_decimals", + type: "uint256" + } + ], + stateMutability: "nonpayable", + type: "constructor" + }, { - internalType: "bool", - name: "", - type: "bool" + inputs: [ + ], + stateMutability: "nonpayable", + type: "function", + name: "acceptTermsOfService" + }, + { + inputs: [ + ], + stateMutability: "view", + type: "function", + name: "readData", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ] + }, + { + inputs: [ + ], + stateMutability: "view", + type: "function", + name: "scalingFactor", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ] } ], - stateMutability: "view", - type: "function" + devdoc: { + kind: "dev", + methods: { + }, + version: 1 + }, + userdoc: { + kind: "user", + methods: { + }, + version: 1 + } + }, + settings: { + remappings: [ + "@api3dao/=lib/contracts/", + "@chainlink/contracts/=node_modules/@chainlink/contracts/", + "@eth-optimism/=node_modules/@eth-optimism/", + "@hebeswap/=lib/hebeswap-contract/", + "@openzeppelin/=lib/openzeppelin-contracts/", + "ds-test/=lib/forge-std/lib/ds-test/src/", + "forge-std/=lib/forge-std/src/", + "hebeswap-contract/=lib/hebeswap-contract/", + "openzeppelin-contracts/=lib/openzeppelin-contracts/", + "solmate/=lib/solmate/src/" + ], + optimizer: { + enabled: true, + runs: 200 + }, + metadata: { + bytecodeHash: "ipfs" + }, + compilationTarget: { + "src/ChainlinkOracle.sol": "ChainlinkOracle" + }, + evmVersion: "prague", + libraries: { + }, + viaIR: true + }, + sources: { + "node_modules/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol": { + keccak256: "0x6e6e4b0835904509406b070ee173b5bc8f677c19421b76be38aea3b1b3d30846", + urls: [ + "bzz-raw://b3beaa37ee61e4ab615e250fbf01601ae481de843fd0ef55e6b44fd9d5fff8a7", + "dweb:/ipfs/QmeZUVwd26LzK4Mfp8Zba5JbQNkZFfTzFu1A6FVMMZDg9c" + ], + license: "MIT" + }, + "src/ChainlinkOracle.sol": { + keccak256: "0xd3a6904bd77d5ee4219b60b519e323268ac4347db771a43bea2c4e2c58b418ad", + urls: [ + "bzz-raw://574ddf2d50bffc03e3457150f00a89105882ec86003405011bca28c76f87e635", + "dweb:/ipfs/QmXBDr2GGd7nnmaC3tbGPm6ASb2ebuqqds1v3rKxD5aDjw" + ], + license: "AEL" + }, + "src/IOracle.sol": { + keccak256: "0xbdb82189368be9100ec49015ca5838207a3bc5bfec11543d0aede20811cb07ad", + urls: [ + "bzz-raw://d6f64b8238eaa188a9b9d7acac753ba0bfccc770b458be512c37c47bc8cafe4c", + "dweb:/ipfs/QmWB2nD9chE3EAKYa4joucZUsFstZNJDjRoDbrdXEKkYk1" + ], + license: "AEL" + } }, + version: 1 + }; + var id$1 = 26; + var chainlinkOracleArtifact = { + abi: abi$1, + bytecode: bytecode$1, + deployedBytecode: deployedBytecode$1, + methodIdentifiers: methodIdentifiers$1, + rawMetadata: rawMetadata$1, + metadata: metadata$1, + id: id$1 + }; + + var abi = [ { + type: "constructor", inputs: [ { - internalType: "address", - name: "", - type: "address" + name: "_proxyAddress", + type: "address", + internalType: "address" }, { - internalType: "uint256", - name: "", - type: "uint256" - } - ], - name: "supporting", - outputs: [ + name: "_api3Decimals", + type: "uint256", + internalType: "uint256" + }, { - internalType: "address", - name: "", - type: "address" + name: "_decimals", + type: "uint256", + internalType: "uint256" } ], - stateMutability: "view", - type: "function" + stateMutability: "nonpayable" }, { + type: "function", + name: "acceptTermsOfService", inputs: [ ], - name: "termsOfService", outputs: [ - { - internalType: "string", - name: "", - type: "string" - } ], - stateMutability: "view", - type: "function" + stateMutability: "nonpayable" }, { + type: "function", + name: "proxyAddress", inputs: [ - { - internalType: "address", - name: "a", - type: "address" - } ], - name: "unoppose", outputs: [ + { + name: "", + type: "address", + internalType: "address" + } ], - stateMutability: "nonpayable", - type: "function" + stateMutability: "view" }, { + type: "function", + name: "readData", inputs: [ - { - internalType: "address", - name: "a", - type: "address" - } ], - name: "unsupport", outputs: [ + { + name: "", + type: "uint256", + internalType: "uint256" + } ], - stateMutability: "nonpayable", - type: "function" + stateMutability: "view" }, { + type: "function", + name: "scalingFactor", inputs: [ - { - internalType: "uint256", - name: "_data", - type: "uint256" - } ], - name: "writeData", outputs: [ + { + name: "", + type: "uint256", + internalType: "uint256" + } ], - stateMutability: "nonpayable", - type: "function" + stateMutability: "view" } ]; - var oracleArtifact = { - contractName: contractName, - abi: abi + var bytecode = { + object: "0x60c060405234156100105760006000fd5b6103b28038038060c00160c0811067ffffffffffffffff8211171561003157fe5b8060405250808260c039606081121561004a5760006000fd5b505060c05173ffffffffffffffffffffffffffffffffffffffff8116811415156100745760006000fd5b60e0516100856101005182846100ba565b505060805160a0516102cc806100e6600039818061011c528061029a52508280606a52806101ed5250806000f35050506100e4565b80608052818310156100c857fe5b818303604d8111156100d657fe5b80600a0a60a052505b505050565bfe6080604052600436101515610149576000803560e01c6323f5c02d81146100465763bef55ef381146100985763dddd9e9681146100d35763ed3437f881146100f857610146565b3415610050578182fd5b61005b366004610153565b61006482610196565b8061008f7f000000000000000000000000000000000000000000000000000000000000000083610169565b0381f350610146565b34156100a2578182fd5b6100ad366004610153565b6100b56101e1565b6100be83610196565b806100c98383610184565b0381f35050610146565b34156100dd578182fd5b6100e8366004610153565b816100f283610196565bf3610146565b3415610102578182fd5b61010d366004610153565b61011682610196565b806101417f000000000000000000000000000000000000000000000000000000000000000083610184565b0381f3505b50505b60006000fd6102cb565b600081830312156101645760006000fd5b5b5050565b60006020820190506001600160a01b03831682525b92915050565b60006020820190508282525b92915050565b6000604051905081810181811067ffffffffffffffff821117156101b657fe5b80604052505b919050565b60008160001904831182151516156101d557fe5b82820290505b92915050565b60006001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016803b1515610219578182fd5b6040516315f789a960e21b8152604081600483855afa9150811515610240573d83843e3d83fd5b82821561029557601f19601f3d011682016040526040823d8401031215610265578384fd5b815180601b0b81141515610277578485fd5b602083015163ffffffff81168114151561028f578586fd5b50809150505b6102c27f000000000000000000000000000000000000000000000000000000000000000082601b0b6101c1565b93505050505b90565b", + sourceMap: "", + linkReferences: { + } + }; + var deployedBytecode = { + object: "0x", + sourceMap: "", + linkReferences: { + } + }; + var methodIdentifiers = { + "acceptTermsOfService()": "dddd9e96", + "proxyAddress()": "23f5c02d", + "readData()": "bef55ef3", + "scalingFactor()": "ed3437f8" + }; + var rawMetadata = "{\"compiler\":{\"version\":\"0.7.6+commit.7338295f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_proxyAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_api3Decimals\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_decimals\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"acceptTermsOfService\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"proxyAddress\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"readData\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"scalingFactor\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/API3Oracle.sol\":\"API3Oracle\"},\"evmVersion\":\"istanbul\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[\":@api3dao/=lib/contracts/\",\":@chainlink/contracts/=node_modules/@chainlink/contracts/\",\":@eth-optimism/=node_modules/@eth-optimism/\",\":@hebeswap/=lib/hebeswap-contract/\",\":@openzeppelin/=lib/openzeppelin-contracts/\",\":ds-test/=lib/forge-std/lib/ds-test/src/\",\":forge-std/=lib/forge-std/src/\",\":hebeswap-contract/=lib/hebeswap-contract/\",\":openzeppelin-contracts/=lib/openzeppelin-contracts/\",\":solmate/=lib/solmate/src/\"],\"viaIR\":true},\"sources\":{\"lib/contracts/contracts/v0.7/interfaces/IProxy.sol\":{\"keccak256\":\"0xb58d1bf2f49358e1a9313aa219df61458778f1c08019cb8d617ad1881a12c39f\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://5553487e888d4f8f5952282f6998b0272127bedfc74cb229e7b8e14636b1ac38\",\"dweb:/ipfs/QmbtEaueqxcfVNwPzTxsRdoBwQKWqcv5UUq5o79o6tCveL\"]},\"src/API3Oracle.sol\":{\"keccak256\":\"0xebf21858eba51f9ac83d4f6104bd076186de755a5342c834544b0a270d32d27b\",\"license\":\"AEL\",\"urls\":[\"bzz-raw://35ada8a00d86957055fb18b1ae7435984c12d8c4ea8b12507458a723af2d1caa\",\"dweb:/ipfs/QmRkz5BKkRDZ3uScuZZQLZ6M2oHxsoud8Xpws9ToPwx1Ub\"]}},\"version\":1}"; + var metadata = { + compiler: { + version: "0.7.6+commit.7338295f" + }, + language: "Solidity", + output: { + abi: [ + { + inputs: [ + { + internalType: "address", + name: "_proxyAddress", + type: "address" + }, + { + internalType: "uint256", + name: "_api3Decimals", + type: "uint256" + }, + { + internalType: "uint256", + name: "_decimals", + type: "uint256" + } + ], + stateMutability: "nonpayable", + type: "constructor" + }, + { + inputs: [ + ], + stateMutability: "nonpayable", + type: "function", + name: "acceptTermsOfService" + }, + { + inputs: [ + ], + stateMutability: "view", + type: "function", + name: "proxyAddress", + outputs: [ + { + internalType: "address", + name: "", + type: "address" + } + ] + }, + { + inputs: [ + ], + stateMutability: "view", + type: "function", + name: "readData", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ] + }, + { + inputs: [ + ], + stateMutability: "view", + type: "function", + name: "scalingFactor", + outputs: [ + { + internalType: "uint256", + name: "", + type: "uint256" + } + ] + } + ], + devdoc: { + kind: "dev", + methods: { + }, + version: 1 + }, + userdoc: { + kind: "user", + methods: { + }, + version: 1 + } + }, + settings: { + remappings: [ + "@api3dao/=lib/contracts/", + "@chainlink/contracts/=node_modules/@chainlink/contracts/", + "@eth-optimism/=node_modules/@eth-optimism/", + "@hebeswap/=lib/hebeswap-contract/", + "@openzeppelin/=lib/openzeppelin-contracts/", + "ds-test/=lib/forge-std/lib/ds-test/src/", + "forge-std/=lib/forge-std/src/", + "hebeswap-contract/=lib/hebeswap-contract/", + "openzeppelin-contracts/=lib/openzeppelin-contracts/", + "solmate/=lib/solmate/src/" + ], + optimizer: { + enabled: true, + runs: 200 + }, + metadata: { + bytecodeHash: "ipfs" + }, + compilationTarget: { + "src/API3Oracle.sol": "API3Oracle" + }, + evmVersion: "istanbul", + libraries: { + }, + viaIR: true + }, + sources: { + "lib/contracts/contracts/v0.7/interfaces/IProxy.sol": { + keccak256: "0xb58d1bf2f49358e1a9313aa219df61458778f1c08019cb8d617ad1881a12c39f", + urls: [ + "bzz-raw://5553487e888d4f8f5952282f6998b0272127bedfc74cb229e7b8e14636b1ac38", + "dweb:/ipfs/QmbtEaueqxcfVNwPzTxsRdoBwQKWqcv5UUq5o79o6tCveL" + ], + license: "MIT" + }, + "src/API3Oracle.sol": { + keccak256: "0xebf21858eba51f9ac83d4f6104bd076186de755a5342c834544b0a270d32d27b", + urls: [ + "bzz-raw://35ada8a00d86957055fb18b1ae7435984c12d8c4ea8b12507458a723af2d1caa", + "dweb:/ipfs/QmRkz5BKkRDZ3uScuZZQLZ6M2oHxsoud8Xpws9ToPwx1Ub" + ], + license: "AEL" + } + }, + version: 1 + }; + var id = 2; + var api3OracleArtifact = { + abi: abi, + bytecode: bytecode, + deployedBytecode: deployedBytecode, + methodIdentifiers: methodIdentifiers, + rawMetadata: rawMetadata, + metadata: metadata, + id: id }; const getOracleAddress = async (djedContract) => { @@ -2270,9 +5117,34 @@ return oracle; }; + const getHebeSwapOracleContract = (web3, oracleAddress, msgSender) => { + const oracle = new web3.eth.Contract(hebeSwapOracleArtifact.abi, oracleAddress, { + from: msgSender + }); + return oracle; + }; + + const getChainlinkOracleContract = (web3, oracleAddress, msgSender) => { + const oracle = new web3.eth.Contract(chainlinkOracleArtifact.abi, oracleAddress, { + from: msgSender + }); + return oracle; + }; + + + const getAPI3OracleContract = (web3, oracleAddress, msgSender) => { + const oracle = new web3.eth.Contract(api3OracleArtifact.abi, oracleAddress, { + from: msgSender + }); + return oracle; + }; + exports.FEE_UI_UNSCALED = FEE_UI_UNSCALED; exports.appendFees = appendFees; + exports.approveTx = approveTx; + exports.buyRcIsisTx = buyRcIsisTx; exports.buyRcTx = buyRcTx; + exports.buyScIsisTx = buyScIsisTx; exports.buyScTx = buyScTx; exports.calculateBcUsdEquivalent = calculateBcUsdEquivalent; exports.calculateFutureScPrice = calculateFutureScPrice; @@ -2280,17 +5152,24 @@ exports.calculateIsRatioBelowMax = calculateIsRatioBelowMax; exports.calculateRcUsdEquivalent = calculateRcUsdEquivalent; exports.calculateTxFees = calculateTxFees; + exports.checkAllowance = checkAllowance; exports.convertToBC = convertToBC; exports.deductFees = deductFees; + exports.getAPI3OracleContract = getAPI3OracleContract; exports.getAccountDetails = getAccountDetails; exports.getBcUsdEquivalent = getBcUsdEquivalent; + exports.getChainlinkOracleContract = getChainlinkOracleContract; exports.getCoinContracts = getCoinContracts; exports.getCoinDetails = getCoinDetails; exports.getDecimals = getDecimals; exports.getDjedContract = getDjedContract; + exports.getDjedIsisContract = getDjedIsisContract; + exports.getDjedTefnutContract = getDjedTefnutContract; exports.getFees = getFees; + exports.getHebeSwapOracleContract = getHebeSwapOracleContract; exports.getOracleAddress = getOracleAddress; exports.getOracleContract = getOracleContract; + exports.getPastDjedEvents = getPastDjedEvents; exports.getRcUsdEquivalent = getRcUsdEquivalent; exports.getScAdaEquivalent = getScAdaEquivalent; exports.getSystemParams = getSystemParams; @@ -2298,11 +5177,17 @@ exports.isTxLimitReached = isTxLimitReached; exports.promiseTx = promiseTx; exports.scalingFactor = scalingFactor; + exports.sellBothIsisTx = sellBothIsisTx; + exports.sellBothTx = sellBothTx; + exports.sellRcIsisTx = sellRcIsisTx; exports.sellRcTx = sellRcTx; + exports.sellScIsisTx = sellScIsisTx; exports.sellScTx = sellScTx; + exports.subscribeToDjedEvents = subscribeToDjedEvents; exports.tradeDataPriceBuyRc = tradeDataPriceBuyRc; exports.tradeDataPriceBuySc = tradeDataPriceBuySc; exports.tradeDataPriceCore = tradeDataPriceCore; + exports.tradeDataPriceSellBoth = tradeDataPriceSellBoth; exports.tradeDataPriceSellRc = tradeDataPriceSellRc; exports.tradeDataPriceSellSc = tradeDataPriceSellSc; exports.verifyTx = verifyTx; diff --git a/djed-sdk/package.json b/djed-sdk/package.json index e6bcdfa..c22dcd0 100644 --- a/djed-sdk/package.json +++ b/djed-sdk/package.json @@ -5,6 +5,7 @@ "main": "dist/umd/index.js", "module": "dist/esm/index.js", "scripts": { + "build": "rollup -c", "test": "echo \"Error: no test specified\" && exit 1" }, "keywords": [], diff --git a/djed-sdk/src/artifacts/API3OracleABI.json b/djed-sdk/src/artifacts/API3OracleABI.json new file mode 100644 index 0000000..cdb3ab6 --- /dev/null +++ b/djed-sdk/src/artifacts/API3OracleABI.json @@ -0,0 +1 @@ +{"abi":[{"type":"constructor","inputs":[{"name":"_proxyAddress","type":"address","internalType":"address"},{"name":"_api3Decimals","type":"uint256","internalType":"uint256"},{"name":"_decimals","type":"uint256","internalType":"uint256"}],"stateMutability":"nonpayable"},{"type":"function","name":"acceptTermsOfService","inputs":[],"outputs":[],"stateMutability":"nonpayable"},{"type":"function","name":"proxyAddress","inputs":[],"outputs":[{"name":"","type":"address","internalType":"address"}],"stateMutability":"view"},{"type":"function","name":"readData","inputs":[],"outputs":[{"name":"","type":"uint256","internalType":"uint256"}],"stateMutability":"view"},{"type":"function","name":"scalingFactor","inputs":[],"outputs":[{"name":"","type":"uint256","internalType":"uint256"}],"stateMutability":"view"}],"bytecode":{"object":"0x60c060405234156100105760006000fd5b6103b28038038060c00160c0811067ffffffffffffffff8211171561003157fe5b8060405250808260c039606081121561004a5760006000fd5b505060c05173ffffffffffffffffffffffffffffffffffffffff8116811415156100745760006000fd5b60e0516100856101005182846100ba565b505060805160a0516102cc806100e6600039818061011c528061029a52508280606a52806101ed5250806000f35050506100e4565b80608052818310156100c857fe5b818303604d8111156100d657fe5b80600a0a60a052505b505050565bfe6080604052600436101515610149576000803560e01c6323f5c02d81146100465763bef55ef381146100985763dddd9e9681146100d35763ed3437f881146100f857610146565b3415610050578182fd5b61005b366004610153565b61006482610196565b8061008f7f000000000000000000000000000000000000000000000000000000000000000083610169565b0381f350610146565b34156100a2578182fd5b6100ad366004610153565b6100b56101e1565b6100be83610196565b806100c98383610184565b0381f35050610146565b34156100dd578182fd5b6100e8366004610153565b816100f283610196565bf3610146565b3415610102578182fd5b61010d366004610153565b61011682610196565b806101417f000000000000000000000000000000000000000000000000000000000000000083610184565b0381f3505b50505b60006000fd6102cb565b600081830312156101645760006000fd5b5b5050565b60006020820190506001600160a01b03831682525b92915050565b60006020820190508282525b92915050565b6000604051905081810181811067ffffffffffffffff821117156101b657fe5b80604052505b919050565b60008160001904831182151516156101d557fe5b82820290505b92915050565b60006001600160a01b037f000000000000000000000000000000000000000000000000000000000000000016803b1515610219578182fd5b6040516315f789a960e21b8152604081600483855afa9150811515610240573d83843e3d83fd5b82821561029557601f19601f3d011682016040526040823d8401031215610265578384fd5b815180601b0b81141515610277578485fd5b602083015163ffffffff81168114151561028f578586fd5b50809150505b6102c27f000000000000000000000000000000000000000000000000000000000000000082601b0b6101c1565b93505050505b90565b","sourceMap":"","linkReferences":{}},"deployedBytecode":{"object":"0x","sourceMap":"","linkReferences":{}},"methodIdentifiers":{"acceptTermsOfService()":"dddd9e96","proxyAddress()":"23f5c02d","readData()":"bef55ef3","scalingFactor()":"ed3437f8"},"rawMetadata":"{\"compiler\":{\"version\":\"0.7.6+commit.7338295f\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_proxyAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_api3Decimals\",\"type\":\"uint256\"},{\"internalType\":\"uint256\",\"name\":\"_decimals\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"acceptTermsOfService\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"proxyAddress\",\"outputs\":[{\"internalType\":\"address\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"readData\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"scalingFactor\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/API3Oracle.sol\":\"API3Oracle\"},\"evmVersion\":\"istanbul\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[\":@api3dao/=lib/contracts/\",\":@chainlink/contracts/=node_modules/@chainlink/contracts/\",\":@eth-optimism/=node_modules/@eth-optimism/\",\":@hebeswap/=lib/hebeswap-contract/\",\":@openzeppelin/=lib/openzeppelin-contracts/\",\":ds-test/=lib/forge-std/lib/ds-test/src/\",\":forge-std/=lib/forge-std/src/\",\":hebeswap-contract/=lib/hebeswap-contract/\",\":openzeppelin-contracts/=lib/openzeppelin-contracts/\",\":solmate/=lib/solmate/src/\"],\"viaIR\":true},\"sources\":{\"lib/contracts/contracts/v0.7/interfaces/IProxy.sol\":{\"keccak256\":\"0xb58d1bf2f49358e1a9313aa219df61458778f1c08019cb8d617ad1881a12c39f\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://5553487e888d4f8f5952282f6998b0272127bedfc74cb229e7b8e14636b1ac38\",\"dweb:/ipfs/QmbtEaueqxcfVNwPzTxsRdoBwQKWqcv5UUq5o79o6tCveL\"]},\"src/API3Oracle.sol\":{\"keccak256\":\"0xebf21858eba51f9ac83d4f6104bd076186de755a5342c834544b0a270d32d27b\",\"license\":\"AEL\",\"urls\":[\"bzz-raw://35ada8a00d86957055fb18b1ae7435984c12d8c4ea8b12507458a723af2d1caa\",\"dweb:/ipfs/QmRkz5BKkRDZ3uScuZZQLZ6M2oHxsoud8Xpws9ToPwx1Ub\"]}},\"version\":1}","metadata":{"compiler":{"version":"0.7.6+commit.7338295f"},"language":"Solidity","output":{"abi":[{"inputs":[{"internalType":"address","name":"_proxyAddress","type":"address"},{"internalType":"uint256","name":"_api3Decimals","type":"uint256"},{"internalType":"uint256","name":"_decimals","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"stateMutability":"nonpayable","type":"function","name":"acceptTermsOfService"},{"inputs":[],"stateMutability":"view","type":"function","name":"proxyAddress","outputs":[{"internalType":"address","name":"","type":"address"}]},{"inputs":[],"stateMutability":"view","type":"function","name":"readData","outputs":[{"internalType":"uint256","name":"","type":"uint256"}]},{"inputs":[],"stateMutability":"view","type":"function","name":"scalingFactor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}]}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"settings":{"remappings":["@api3dao/=lib/contracts/","@chainlink/contracts/=node_modules/@chainlink/contracts/","@eth-optimism/=node_modules/@eth-optimism/","@hebeswap/=lib/hebeswap-contract/","@openzeppelin/=lib/openzeppelin-contracts/","ds-test/=lib/forge-std/lib/ds-test/src/","forge-std/=lib/forge-std/src/","hebeswap-contract/=lib/hebeswap-contract/","openzeppelin-contracts/=lib/openzeppelin-contracts/","solmate/=lib/solmate/src/"],"optimizer":{"enabled":true,"runs":200},"metadata":{"bytecodeHash":"ipfs"},"compilationTarget":{"src/API3Oracle.sol":"API3Oracle"},"evmVersion":"istanbul","libraries":{},"viaIR":true},"sources":{"lib/contracts/contracts/v0.7/interfaces/IProxy.sol":{"keccak256":"0xb58d1bf2f49358e1a9313aa219df61458778f1c08019cb8d617ad1881a12c39f","urls":["bzz-raw://5553487e888d4f8f5952282f6998b0272127bedfc74cb229e7b8e14636b1ac38","dweb:/ipfs/QmbtEaueqxcfVNwPzTxsRdoBwQKWqcv5UUq5o79o6tCveL"],"license":"MIT"},"src/API3Oracle.sol":{"keccak256":"0xebf21858eba51f9ac83d4f6104bd076186de755a5342c834544b0a270d32d27b","urls":["bzz-raw://35ada8a00d86957055fb18b1ae7435984c12d8c4ea8b12507458a723af2d1caa","dweb:/ipfs/QmRkz5BKkRDZ3uScuZZQLZ6M2oHxsoud8Xpws9ToPwx1Ub"],"license":"AEL"}},"version":1},"id":2} \ No newline at end of file diff --git a/djed-sdk/src/artifacts/ChainlinkOracleABI.json b/djed-sdk/src/artifacts/ChainlinkOracleABI.json new file mode 100644 index 0000000..4b8e3aa --- /dev/null +++ b/djed-sdk/src/artifacts/ChainlinkOracleABI.json @@ -0,0 +1 @@ +{"abi":[{"type":"constructor","inputs":[{"name":"_dataFeedAddress","type":"address","internalType":"address"},{"name":"_decimals","type":"uint256","internalType":"uint256"}],"stateMutability":"nonpayable"},{"type":"function","name":"acceptTermsOfService","inputs":[],"outputs":[],"stateMutability":"nonpayable"},{"type":"function","name":"readData","inputs":[],"outputs":[{"name":"","type":"uint256","internalType":"uint256"}],"stateMutability":"view"},{"type":"function","name":"scalingFactor","inputs":[],"outputs":[{"name":"","type":"uint256","internalType":"uint256"}],"stateMutability":"view"}],"bytecode":{"object":"0x60a0806040523461010057604081610333803803809161001f8285610117565b8339810103126101005780516001600160a01b0381169190829003610100576020908101515f80546001600160a01b0319168417905560405163313ce56760e01b81529092909190829060049082905afa801561010c575f906100cb575b60ff9150169081039081116100b757604d81116100b757600a0a6080526040516101e4908161014f82396080518181816054015260cf0152f35b634e487b7160e01b5f52601160045260245ffd5b506020813d602011610104575b816100e560209383610117565b81010312610100575160ff811681036101005760ff9061007d565b5f80fd5b3d91506100d8565b6040513d5f823e3d90fd5b601f909101601f19168101906001600160401b0382119082101761013a57604052565b634e487b7160e01b5f52604160045260245ffdfe6080806040526004361015610012575f80fd5b5f3560e01c908163bef55ef31461008d57508063dddd9e961461007b5763ed3437f81461003d575f80fd5b34610077575f3660031901126100775760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b5f80fd5b34610077575f36600319011261007757005b34610077575f366003190112610077575f54633fabe5a360e21b825260a090829060049082906001600160a01b03165afa90811561018c575f91610115575b507f00000000000000000000000000000000000000000000000000000000000000009081156101015760209160405191048152f35b634e487b7160e01b5f52601260045260245ffd5b905060a03d60a011610185575b601f8101601f1916820167ffffffffffffffff8111838210176101715760a0918391604052810103126100775761015881610197565b5061016a608060208301519201610197565b50816100cc565b634e487b7160e01b5f52604160045260245ffd5b503d610122565b6040513d5f823e3d90fd5b519069ffffffffffffffffffff821682036100775756fea26469706673582212209673ddeb55b798f5094586c6147a71d254ed39e9b38245e74cfdcd015b47b0cf64736f6c63430008210033","sourceMap":"159:564:26:-:0;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;-1:-1:-1;;;;;159:564:26;;;;;;;;;;;;;;-1:-1:-1;159:564:26;;-1:-1:-1;;;;;;159:564:26;;;;;;;-1:-1:-1;;;447:19:26;;159:564;;;;;;;447:19;;159:564;;447:19;;;;;;-1:-1:-1;447:19:26;;;-1:-1:-1;159:564:26;;;;;;;;;;;;;;;;;;;418:62;;159:564;;;;;;;;418:62;159:564;;;;;;;;;;;;;;;-1:-1:-1;159:564:26;;447:19;159:564;;-1:-1:-1;159:564:26;447:19;;159:564;447:19;;159:564;447:19;;;;;;159:564;447:19;;;:::i;:::-;;;159:564;;;;;;;;;;;;;447:19;;;159:564;-1:-1:-1;159:564:26;;447:19;;;-1:-1:-1;447:19:26;;;159:564;;;-1:-1:-1;159:564:26;;;;;;;;;;-1:-1:-1;;159:564:26;;;;-1:-1:-1;;;;;159:564:26;;;;;;;;;;:::o;:::-;;;;-1:-1:-1;159:564:26;;;;;-1:-1:-1;159:564:26","linkReferences":{}},"deployedBytecode":{"object":"0x6080806040526004361015610012575f80fd5b5f3560e01c908163bef55ef31461008d57508063dddd9e961461007b5763ed3437f81461003d575f80fd5b34610077575f3660031901126100775760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b5f80fd5b34610077575f36600319011261007757005b34610077575f366003190112610077575f54633fabe5a360e21b825260a090829060049082906001600160a01b03165afa90811561018c575f91610115575b507f00000000000000000000000000000000000000000000000000000000000000009081156101015760209160405191048152f35b634e487b7160e01b5f52601260045260245ffd5b905060a03d60a011610185575b601f8101601f1916820167ffffffffffffffff8111838210176101715760a0918391604052810103126100775761015881610197565b5061016a608060208301519201610197565b50816100cc565b634e487b7160e01b5f52604160045260245ffd5b503d610122565b6040513d5f823e3d90fd5b519069ffffffffffffffffffff821682036100775756fea26469706673582212209673ddeb55b798f5094586c6147a71d254ed39e9b38245e74cfdcd015b47b0cf64736f6c63430008210033","sourceMap":"159:564:26:-:0;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;159:564:26;;;;;;;246:38;159:564;;;;;;;;;;;;;-1:-1:-1;;159:564:26;;;;;;;;;;;-1:-1:-1;;159:564:26;;;;;;-1:-1:-1;;;630:26:26;;;;159:564;;;;;;-1:-1:-1;;;;;159:564:26;630:26;;;;;;;159:564;630:26;;;159:564;700:13;;159:564;;;;;;;;;;;;;;;;;;;;;;;;;;630:26;;;;;;;;;;159:564;;;-1:-1:-1;;159:564:26;;;;;;;;;;;;630:26;159:564;;;;;630:26;;159:564;;;;;;;:::i;:::-;;;;;;;;;;;:::i;:::-;;630:26;;;159:564;;;;;;;;;;;;630:26;;;;;;159:564;;;;;;;;;;;;;;;;;;;:::o","linkReferences":{},"immutableReferences":{"45104":[{"start":84,"length":32},{"start":207,"length":32}]}},"methodIdentifiers":{"acceptTermsOfService()":"dddd9e96","readData()":"bef55ef3","scalingFactor()":"ed3437f8"},"rawMetadata":"{\"compiler\":{\"version\":\"0.8.33+commit.64118f21\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"address\",\"name\":\"_dataFeedAddress\",\"type\":\"address\"},{\"internalType\":\"uint256\",\"name\":\"_decimals\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"acceptTermsOfService\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"readData\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"scalingFactor\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/ChainlinkOracle.sol\":\"ChainlinkOracle\"},\"evmVersion\":\"prague\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[\":@api3dao/=lib/contracts/\",\":@chainlink/contracts/=node_modules/@chainlink/contracts/\",\":@eth-optimism/=node_modules/@eth-optimism/\",\":@hebeswap/=lib/hebeswap-contract/\",\":@openzeppelin/=lib/openzeppelin-contracts/\",\":ds-test/=lib/forge-std/lib/ds-test/src/\",\":forge-std/=lib/forge-std/src/\",\":hebeswap-contract/=lib/hebeswap-contract/\",\":openzeppelin-contracts/=lib/openzeppelin-contracts/\",\":solmate/=lib/solmate/src/\"],\"viaIR\":true},\"sources\":{\"node_modules/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol\":{\"keccak256\":\"0x6e6e4b0835904509406b070ee173b5bc8f677c19421b76be38aea3b1b3d30846\",\"license\":\"MIT\",\"urls\":[\"bzz-raw://b3beaa37ee61e4ab615e250fbf01601ae481de843fd0ef55e6b44fd9d5fff8a7\",\"dweb:/ipfs/QmeZUVwd26LzK4Mfp8Zba5JbQNkZFfTzFu1A6FVMMZDg9c\"]},\"src/ChainlinkOracle.sol\":{\"keccak256\":\"0xd3a6904bd77d5ee4219b60b519e323268ac4347db771a43bea2c4e2c58b418ad\",\"license\":\"AEL\",\"urls\":[\"bzz-raw://574ddf2d50bffc03e3457150f00a89105882ec86003405011bca28c76f87e635\",\"dweb:/ipfs/QmXBDr2GGd7nnmaC3tbGPm6ASb2ebuqqds1v3rKxD5aDjw\"]},\"src/IOracle.sol\":{\"keccak256\":\"0xbdb82189368be9100ec49015ca5838207a3bc5bfec11543d0aede20811cb07ad\",\"license\":\"AEL\",\"urls\":[\"bzz-raw://d6f64b8238eaa188a9b9d7acac753ba0bfccc770b458be512c37c47bc8cafe4c\",\"dweb:/ipfs/QmWB2nD9chE3EAKYa4joucZUsFstZNJDjRoDbrdXEKkYk1\"]}},\"version\":1}","metadata":{"compiler":{"version":"0.8.33+commit.64118f21"},"language":"Solidity","output":{"abi":[{"inputs":[{"internalType":"address","name":"_dataFeedAddress","type":"address"},{"internalType":"uint256","name":"_decimals","type":"uint256"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"stateMutability":"nonpayable","type":"function","name":"acceptTermsOfService"},{"inputs":[],"stateMutability":"view","type":"function","name":"readData","outputs":[{"internalType":"uint256","name":"","type":"uint256"}]},{"inputs":[],"stateMutability":"view","type":"function","name":"scalingFactor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}]}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"settings":{"remappings":["@api3dao/=lib/contracts/","@chainlink/contracts/=node_modules/@chainlink/contracts/","@eth-optimism/=node_modules/@eth-optimism/","@hebeswap/=lib/hebeswap-contract/","@openzeppelin/=lib/openzeppelin-contracts/","ds-test/=lib/forge-std/lib/ds-test/src/","forge-std/=lib/forge-std/src/","hebeswap-contract/=lib/hebeswap-contract/","openzeppelin-contracts/=lib/openzeppelin-contracts/","solmate/=lib/solmate/src/"],"optimizer":{"enabled":true,"runs":200},"metadata":{"bytecodeHash":"ipfs"},"compilationTarget":{"src/ChainlinkOracle.sol":"ChainlinkOracle"},"evmVersion":"prague","libraries":{},"viaIR":true},"sources":{"node_modules/@chainlink/contracts/src/v0.8/interfaces/AggregatorV3Interface.sol":{"keccak256":"0x6e6e4b0835904509406b070ee173b5bc8f677c19421b76be38aea3b1b3d30846","urls":["bzz-raw://b3beaa37ee61e4ab615e250fbf01601ae481de843fd0ef55e6b44fd9d5fff8a7","dweb:/ipfs/QmeZUVwd26LzK4Mfp8Zba5JbQNkZFfTzFu1A6FVMMZDg9c"],"license":"MIT"},"src/ChainlinkOracle.sol":{"keccak256":"0xd3a6904bd77d5ee4219b60b519e323268ac4347db771a43bea2c4e2c58b418ad","urls":["bzz-raw://574ddf2d50bffc03e3457150f00a89105882ec86003405011bca28c76f87e635","dweb:/ipfs/QmXBDr2GGd7nnmaC3tbGPm6ASb2ebuqqds1v3rKxD5aDjw"],"license":"AEL"},"src/IOracle.sol":{"keccak256":"0xbdb82189368be9100ec49015ca5838207a3bc5bfec11543d0aede20811cb07ad","urls":["bzz-raw://d6f64b8238eaa188a9b9d7acac753ba0bfccc770b458be512c37c47bc8cafe4c","dweb:/ipfs/QmWB2nD9chE3EAKYa4joucZUsFstZNJDjRoDbrdXEKkYk1"],"license":"AEL"}},"version":1},"id":26} \ No newline at end of file diff --git a/djed-sdk/src/artifacts/DjedABI.json b/djed-sdk/src/artifacts/DjedABI.json index ed248b8..ac55db8 100644 --- a/djed-sdk/src/artifacts/DjedABI.json +++ b/djed-sdk/src/artifacts/DjedABI.json @@ -1,6 +1,6 @@ { "contractName": "Djed", -"abi": [ + "abi": [ { "inputs": [ { @@ -699,6 +699,77 @@ ], "stateMutability": "view", "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_currentPaymentAmount", + "type": "uint256" + } + ], + "name": "scMaxPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_currentPaymentAmount", + "type": "uint256" + } + ], + "name": "scMinPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ratioMax", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ratioMin", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "updateOracleValues", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" } ] } \ No newline at end of file diff --git a/djed-sdk/src/artifacts/DjedIsisABI.json b/djed-sdk/src/artifacts/DjedIsisABI.json new file mode 100644 index 0000000..38e2a0b --- /dev/null +++ b/djed-sdk/src/artifacts/DjedIsisABI.json @@ -0,0 +1,785 @@ +{ + "contractName": "Djed", + "abi": [ + { + "inputs": [ + { + "internalType": "address", + "name": "oracleAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_scalingFactor", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_treasury", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_initialTreasuryFee", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_treasuryRevenueTarget", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_reserveRatioMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_reserveRatioMax", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_fee", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_thresholdSupplySC", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_rcMinPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_txLimit", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "buyer", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountRC", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountBC", + "type": "uint256" + } + ], + "name": "BoughtReserveCoins", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "buyer", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountSC", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountBC", + "type": "uint256" + } + ], + "name": "BoughtStableCoins", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "seller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountSC", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountRC", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountBC", + "type": "uint256" + } + ], + "name": "SoldBothCoins", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "seller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountRC", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountBC", + "type": "uint256" + } + ], + "name": "SoldReserveCoins", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "seller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountSC", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountBC", + "type": "uint256" + } + ], + "name": "SoldStableCoins", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_currentPaymentAmount", + "type": "uint256" + } + ], + "name": "E", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "L", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_currentPaymentAmount", + "type": "uint256" + } + ], + "name": "R", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "uint256", + "name": "fee_ui", + "type": "uint256" + }, + { + "internalType": "address", + "name": "ui", + "type": "address" + } + ], + "name": "buyReserveCoins", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "uint256", + "name": "feeUI", + "type": "uint256" + }, + { + "internalType": "address", + "name": "ui", + "type": "address" + } + ], + "name": "buyStableCoins", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "fee", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "initialTreasuryFee", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "oracle", + "outputs": [ + { + "internalType": "contract IFreeOracle", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ratio", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_currentPaymentAmount", + "type": "uint256" + } + ], + "name": "rcBuyingPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "rcDecimalScalingFactor", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "rcMinPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_currentPaymentAmount", + "type": "uint256" + } + ], + "name": "rcTargetPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "reserveCoin", + "outputs": [ + { + "internalType": "contract Coin", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "reserveRatioMax", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "reserveRatioMin", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "scDecimalScalingFactor", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_currentPaymentAmount", + "type": "uint256" + } + ], + "name": "scPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "scalingFactor", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountSC", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountRC", + "type": "uint256" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "uint256", + "name": "fee_ui", + "type": "uint256" + }, + { + "internalType": "address", + "name": "ui", + "type": "address" + } + ], + "name": "sellBothCoins", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountRC", + "type": "uint256" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "uint256", + "name": "fee_ui", + "type": "uint256" + }, + { + "internalType": "address", + "name": "ui", + "type": "address" + } + ], + "name": "sellReserveCoins", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountSC", + "type": "uint256" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "uint256", + "name": "feeUI", + "type": "uint256" + }, + { + "internalType": "address", + "name": "ui", + "type": "address" + } + ], + "name": "sellStableCoins", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "stableCoin", + "outputs": [ + { + "internalType": "contract Coin", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "thresholdSupplySC", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "treasury", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "treasuryFee", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "treasuryRevenue", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "treasuryRevenueTarget", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "txLimit", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_currentPaymentAmount", + "type": "uint256" + } + ], + "name": "scMaxPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_currentPaymentAmount", + "type": "uint256" + } + ], + "name": "scMinPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ratioMax", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ratioMin", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "updateOracleValues", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } + ] +} \ No newline at end of file diff --git a/djed-sdk/src/artifacts/DjedTefnutABI.json b/djed-sdk/src/artifacts/DjedTefnutABI.json new file mode 100644 index 0000000..38e2a0b --- /dev/null +++ b/djed-sdk/src/artifacts/DjedTefnutABI.json @@ -0,0 +1,785 @@ +{ + "contractName": "Djed", + "abi": [ + { + "inputs": [ + { + "internalType": "address", + "name": "oracleAddress", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_scalingFactor", + "type": "uint256" + }, + { + "internalType": "address", + "name": "_treasury", + "type": "address" + }, + { + "internalType": "uint256", + "name": "_initialTreasuryFee", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_treasuryRevenueTarget", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_reserveRatioMin", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_reserveRatioMax", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_fee", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_thresholdSupplySC", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_rcMinPrice", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "_txLimit", + "type": "uint256" + } + ], + "stateMutability": "payable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "buyer", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountRC", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountBC", + "type": "uint256" + } + ], + "name": "BoughtReserveCoins", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "buyer", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountSC", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountBC", + "type": "uint256" + } + ], + "name": "BoughtStableCoins", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "seller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountSC", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountRC", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountBC", + "type": "uint256" + } + ], + "name": "SoldBothCoins", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "seller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountRC", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountBC", + "type": "uint256" + } + ], + "name": "SoldReserveCoins", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "seller", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountSC", + "type": "uint256" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "amountBC", + "type": "uint256" + } + ], + "name": "SoldStableCoins", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_currentPaymentAmount", + "type": "uint256" + } + ], + "name": "E", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "L", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_currentPaymentAmount", + "type": "uint256" + } + ], + "name": "R", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "uint256", + "name": "fee_ui", + "type": "uint256" + }, + { + "internalType": "address", + "name": "ui", + "type": "address" + } + ], + "name": "buyReserveCoins", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "uint256", + "name": "feeUI", + "type": "uint256" + }, + { + "internalType": "address", + "name": "ui", + "type": "address" + } + ], + "name": "buyStableCoins", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "fee", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "initialTreasuryFee", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "oracle", + "outputs": [ + { + "internalType": "contract IFreeOracle", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ratio", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_currentPaymentAmount", + "type": "uint256" + } + ], + "name": "rcBuyingPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "rcDecimalScalingFactor", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "rcMinPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_currentPaymentAmount", + "type": "uint256" + } + ], + "name": "rcTargetPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "reserveCoin", + "outputs": [ + { + "internalType": "contract Coin", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "reserveRatioMax", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "reserveRatioMin", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "scDecimalScalingFactor", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_currentPaymentAmount", + "type": "uint256" + } + ], + "name": "scPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "scalingFactor", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountSC", + "type": "uint256" + }, + { + "internalType": "uint256", + "name": "amountRC", + "type": "uint256" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "uint256", + "name": "fee_ui", + "type": "uint256" + }, + { + "internalType": "address", + "name": "ui", + "type": "address" + } + ], + "name": "sellBothCoins", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountRC", + "type": "uint256" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "uint256", + "name": "fee_ui", + "type": "uint256" + }, + { + "internalType": "address", + "name": "ui", + "type": "address" + } + ], + "name": "sellReserveCoins", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "amountSC", + "type": "uint256" + }, + { + "internalType": "address", + "name": "receiver", + "type": "address" + }, + { + "internalType": "uint256", + "name": "feeUI", + "type": "uint256" + }, + { + "internalType": "address", + "name": "ui", + "type": "address" + } + ], + "name": "sellStableCoins", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "stableCoin", + "outputs": [ + { + "internalType": "contract Coin", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "thresholdSupplySC", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "treasury", + "outputs": [ + { + "internalType": "address", + "name": "", + "type": "address" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "treasuryFee", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "treasuryRevenue", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "treasuryRevenueTarget", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "txLimit", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_currentPaymentAmount", + "type": "uint256" + } + ], + "name": "scMaxPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "uint256", + "name": "_currentPaymentAmount", + "type": "uint256" + } + ], + "name": "scMinPrice", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ratioMax", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "ratioMin", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "updateOracleValues", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } + ] +} \ No newline at end of file diff --git a/djed-sdk/src/artifacts/HebeSwapOracleABI.json b/djed-sdk/src/artifacts/HebeSwapOracleABI.json new file mode 100644 index 0000000..f0bcdb7 --- /dev/null +++ b/djed-sdk/src/artifacts/HebeSwapOracleABI.json @@ -0,0 +1 @@ +{"abi":[{"type":"constructor","inputs":[{"name":"_ref","type":"address","internalType":"contract IStdReference"},{"name":"_decimals","type":"uint8","internalType":"uint8"},{"name":"_hebeSwapDecimals","type":"uint8","internalType":"uint8"},{"name":"_baseToken","type":"string","internalType":"string"},{"name":"_quoteToken","type":"string","internalType":"string"}],"stateMutability":"nonpayable"},{"type":"function","name":"acceptTermsOfService","inputs":[],"outputs":[],"stateMutability":"nonpayable"},{"type":"function","name":"baseToken","inputs":[],"outputs":[{"name":"","type":"string","internalType":"string"}],"stateMutability":"view"},{"type":"function","name":"quoteToken","inputs":[],"outputs":[{"name":"","type":"string","internalType":"string"}],"stateMutability":"view"},{"type":"function","name":"readData","inputs":[],"outputs":[{"name":"","type":"uint256","internalType":"uint256"}],"stateMutability":"view"},{"type":"function","name":"ref","inputs":[],"outputs":[{"name":"","type":"address","internalType":"contract IStdReference"}],"stateMutability":"view"},{"type":"function","name":"scalingFactor","inputs":[],"outputs":[{"name":"","type":"uint256","internalType":"uint256"}],"stateMutability":"view"}],"bytecode":{"object":"0x60c060405234620000db5762000b08803803806200001d81620000f7565b928339810160a082820312620000db578151906001600160a01b0382168203620000db576200004f602084016200012c565b6200005d604085016200012c565b60608501516001600160401b039591929190868111620000db5784620000859183016200013b565b936080820151968711620000db57620000ab96620000a492016200013b565b93620003d9565b6040516105d1908162000537823960805181818161037201526103f7015260a05181818161043501526104fe0152f35b600080fd5b50634e487b7160e01b600052604160045260246000fd5b6040519190601f01601f191682016001600160401b038111838210176200011d57604052565b62000127620000e0565b604052565b519060ff82168203620000db57565b81601f82011215620000db578051906001600160401b038211620001bf575b60209062000171601f8401601f19168301620000f7565b93838552828483010111620000db5782906000905b83838310620001a6575050116200019c57505090565b6000918301015290565b8193508281939201015182828801015201839162000186565b620001c9620000e0565b6200015a565b50634e487b7160e01b600052601160045260246000fd5b90600182811c9216801562000218575b60208310146200020257565b634e487b7160e01b600052602260045260246000fd5b91607f1691620001f6565b601f811162000230575050565b60009081805260208220906020601f850160051c8301941062000270575b601f0160051c01915b8281106200026457505050565b81815560010162000257565b90925082906200024e565b90601f821162000289575050565b60019160009083825260208220906020601f850160051c83019410620002cc575b601f0160051c01915b828110620002c15750505050565b8181558301620002b3565b9092508290620002aa565b80519091906001600160401b038111620003c9575b6001906200030681620003008454620001e6565b6200027b565b602080601f83116001146200034457508192939460009262000338575b5050600019600383901b1c191690821b179055565b01519050388062000323565b6001600052601f198316959091907fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6926000905b888210620003b1575050838596971062000397575b505050811b019055565b015160001960f88460031b161c191690553880806200038d565b80878596829496860151815501950193019062000378565b620003d3620000e0565b620002ec565b6080529193929160ff91821690821681811062000526575b0316604d811162000516575b600a0a60a05282516001600160401b03811162000506575b6000906200042f81620004298454620001e6565b62000223565b602080601f8311600114620004775750819062000469959684926200046b575b50508160011b916000199060031b1c1916179055620002d7565b565b0151905038806200044f565b60008052601f198316967f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563929185905b898210620004ed5750509083929160019462000469989910620004d3575b505050811b019055620002d7565b015160001960f88460031b161c19169055388080620004c5565b80600185968294968601518155019501930190620004a7565b62000510620000e0565b62000415565b62000520620001cf565b620003fd565b62000530620001cf565b620003f156fe60806040526004361015610013575b600080fd5b6000803560e01c908163217a4b701461008e5750806321a78f6814610085578063bef55ef31461007c578063c55dae6314610073578063dddd9e961461006a5763ed3437f81461006257600080fd5b61000e6104e5565b5061000e6104d1565b5061000e6104a5565b5061000e6103a1565b5061000e61035b565b346100b957806003193601126100b9576100b56100a961024e565b60405191829182610304565b0390f35b80fd5b90600182811c921680156100ec575b60208310146100d657565b634e487b7160e01b600052602260045260246000fd5b91607f16916100cb565b9060009160005490610107826100bc565b8082529160019081811690811561017d575060011461012557505050565b91929350600080527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563916000925b84841061016557505060209250010190565b80546020858501810191909152909301928101610153565b60ff191660208401525050604001925050565b906000916001908154916101a3836100bc565b8083529281811690811561017d57506001146101be57505050565b80929394506000527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6916000925b8484106101fe57505060209250010190565b805460208585018101919091529093019281016101ec565b90601f8019910116810190811067ffffffffffffffff82111761023857604052565b634e487b7160e01b600052604160045260246000fd5b604051600081600191825492610263846100bc565b808452938181169081156102e7575060011461028a575b5061028792500382610216565b90565b600081815291507fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf65b8483106102cc575061028793505081016020013861027a565b819350908160209254838589010152019101909184926102b3565b94505050505060ff1916602082015261028781604081013861027a565b919091602080825283519081818401526000945b828610610345575050806040939411610338575b601f01601f1916010190565b600083828401015261032c565b8581018201518487016040015294810194610318565b503461000e57600036600319011261000e576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b503461000e5760031960003682011261000e5761045a6103f360606100b5936040518093819263195556f360e21b8352604060048401526103e4604484016100f6565b90838203016024840152610190565b03817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610498575b60009161046a575b50517f000000000000000000000000000000000000000000000000000000000000000090610572565b6040519081529081906020820190565b61048b915060603d8111610491575b6104838183610216565b810190610521565b38610431565b503d610479565b6104a0610565565b610429565b503461000e57600036600319011261000e576100b56040516100a9816104ca816100f6565b0382610216565b503461000e57600036600319011261000e57005b503461000e57600036600319011261000e5760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b9081606091031261000e5760405190606082019082821067ffffffffffffffff83111761023857604091825280518352602081015160208401520151604082015290565b506040513d6000823e3d90fd5b8060001904821181151516610585570290565b634e487b7160e01b600052601160045260246000fdfea264697066735822122053cfb7b37092c28d461cf6387ad085646c5cf4ccd06822d58ce0f7819d82b38b64736f6c634300080d0033","sourceMap":"120:827:2:-:0;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;-1:-1:-1;;;;;120:827:2;;;;;;;;;;;:::i;:::-;;;;;;:::i;:::-;;;;;-1:-1:-1;;;;;120:827:2;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;:::i;:::-;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;120:827:2;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;120:827:2;;;-1:-1:-1;;;;;120:827:2;;;;;;;;;;:::o;:::-;;;:::i;:::-;;;:::o;:::-;;;;;;;;;;:::o;:::-;;;;;;;;;;;;-1:-1:-1;;;;;120:827:2;;;;;;;;;;;-1:-1:-1;;120:827:2;;;;:::i;:::-;;;;;;;;;;;;;;;-1:-1:-1;120:827:2;;;;;;;;;;;;;;;;:::o;:::-;-1:-1:-1;120:827:2;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;578:22;120:827;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;-1:-1:-1;120:827:2;;;;;;;;;;;;;:::o;:::-;610:24;-1:-1:-1;;120:827:2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;-1:-1:-1;120:827:2;;;;;;;;;;-1:-1:-1;;;;;120:827:2;;;;;;;;;;;;;:::i;:::-;;:::i;:::-;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;;;120:827:2;;;;;;;;;;;;;:::o;:::-;;;;-1:-1:-1;120:827:2;;;;;610:24;120:827;;-1:-1:-1;;120:827:2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;305:336;488:10;;305:336;;;;120:827;;;;;;;;;;;;305:336;120:827;;;;;;;305:336;120:827;;508:60;;120:827;;-1:-1:-1;;;;;120:827:2;;;;305:336;-1:-1:-1;120:827:2;;;;;;;:::i;:::-;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;305:336::o;120:827::-;;;;-1:-1:-1;120:827:2;;;;;578:22;120:827;;-1:-1:-1;;120:827:2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;:::i;:::-;;;;;;:::i;:::-;;","linkReferences":{}},"deployedBytecode":{"object":"0x60806040526004361015610013575b600080fd5b6000803560e01c908163217a4b701461008e5750806321a78f6814610085578063bef55ef31461007c578063c55dae6314610073578063dddd9e961461006a5763ed3437f81461006257600080fd5b61000e6104e5565b5061000e6104d1565b5061000e6104a5565b5061000e6103a1565b5061000e61035b565b346100b957806003193601126100b9576100b56100a961024e565b60405191829182610304565b0390f35b80fd5b90600182811c921680156100ec575b60208310146100d657565b634e487b7160e01b600052602260045260246000fd5b91607f16916100cb565b9060009160005490610107826100bc565b8082529160019081811690811561017d575060011461012557505050565b91929350600080527f290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563916000925b84841061016557505060209250010190565b80546020858501810191909152909301928101610153565b60ff191660208401525050604001925050565b906000916001908154916101a3836100bc565b8083529281811690811561017d57506001146101be57505050565b80929394506000527fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf6916000925b8484106101fe57505060209250010190565b805460208585018101919091529093019281016101ec565b90601f8019910116810190811067ffffffffffffffff82111761023857604052565b634e487b7160e01b600052604160045260246000fd5b604051600081600191825492610263846100bc565b808452938181169081156102e7575060011461028a575b5061028792500382610216565b90565b600081815291507fb10e2d527612073b26eecdfd717e6a320cf44b4afac2b0732d9fcbe2b7fa0cf65b8483106102cc575061028793505081016020013861027a565b819350908160209254838589010152019101909184926102b3565b94505050505060ff1916602082015261028781604081013861027a565b919091602080825283519081818401526000945b828610610345575050806040939411610338575b601f01601f1916010190565b600083828401015261032c565b8581018201518487016040015294810194610318565b503461000e57600036600319011261000e576040517f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03168152602090f35b503461000e5760031960003682011261000e5761045a6103f360606100b5936040518093819263195556f360e21b8352604060048401526103e4604484016100f6565b90838203016024840152610190565b03817f00000000000000000000000000000000000000000000000000000000000000006001600160a01b03165afa908115610498575b60009161046a575b50517f000000000000000000000000000000000000000000000000000000000000000090610572565b6040519081529081906020820190565b61048b915060603d8111610491575b6104838183610216565b810190610521565b38610431565b503d610479565b6104a0610565565b610429565b503461000e57600036600319011261000e576100b56040516100a9816104ca816100f6565b0382610216565b503461000e57600036600319011261000e57005b503461000e57600036600319011261000e5760206040517f00000000000000000000000000000000000000000000000000000000000000008152f35b9081606091031261000e5760405190606082019082821067ffffffffffffffff83111761023857604091825280518352602081015160208401520151604082015290565b506040513d6000823e3d90fd5b8060001904821181151516610585570290565b634e487b7160e01b600052601160045260246000fdfea264697066735822122053cfb7b37092c28d461cf6387ad085646c5cf4ccd06822d58ce0f7819d82b38b64736f6c634300080d0033","sourceMap":"120:827:2:-:0;;;;;;;;;-1:-1:-1;120:827:2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;:::i;:::-;;;;:::i;:::-;;;;:::i;:::-;;;;;;;;;;;;;274:24;;:::i;:::-;120:827;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::i;:::-;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;120:827:2;;;;;-1:-1:-1;;120:827:2;;;-1:-1:-1;;120:827:2:o;:::-;;;;857:10;120:827;;;;;;;:::i;:::-;;;;;;;;;857:10;;;;120:827;;;;;;;;:::o;:::-;;;;;;-1:-1:-1;120:827:2;;;-1:-1:-1;120:827:2;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;-1:-1:-1;274:24:2;;120:827;;;;;;;:::i;:::-;;;;;;;;;274:24;;;;120:827;;;;;;;;;;;;;:::i;:::-;;:::o;:::-;-1:-1:-1;120:827:2;;;-1:-1:-1;;120:827:2;;;;;;;-1:-1:-1;120:827:2;;-1:-1:-1;;120:827:2;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;120:827:2;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;-1:-1:-1;;120:827:2;;;;;;161:34;-1:-1:-1;;;;;120:827:2;;;;;;;;;;;-1:-1:-1;;120:827:2;;;;;;;895:42;120:827;800:77;120:827;;;;;;;;;;;800:77;;120:827;;800:77;;120:827;;;;;;:::i;:::-;;;;;;;;;;;:::i;:::-;800:77;120:827;800:3;-1:-1:-1;;;;;120:827:2;800:77;;;;;;;120:827;;800:77;;;120:827;;;924:13;895:42;;:::i;:::-;120:827;;;;;;;;;;;;;800:77;;;;;;;;;;;;;;;:::i;:::-;;;;;:::i;:::-;;;;;;;;;;;;:::i;:::-;;;120:827;;;;;;;-1:-1:-1;;120:827:2;;;;;;;;;;;;:::i;:::-;;;;:::i;:::-;;;;;;;-1:-1:-1;;120:827:2;;;;;;;;;;;;-1:-1:-1;;120:827:2;;;;;;;201:38;120:827;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;;;;;;;;;;;;;;;;:::o;:::-;;;;;;;;;;;","linkReferences":{},"immutableReferences":{"131":[{"start":882,"length":32},{"start":1015,"length":32}],"133":[{"start":1077,"length":32},{"start":1278,"length":32}]}},"methodIdentifiers":{"acceptTermsOfService()":"dddd9e96","baseToken()":"c55dae63","quoteToken()":"217a4b70","readData()":"bef55ef3","ref()":"21a78f68","scalingFactor()":"ed3437f8"},"rawMetadata":"{\"compiler\":{\"version\":\"0.8.13+commit.abaa5c0e\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[{\"internalType\":\"contract IStdReference\",\"name\":\"_ref\",\"type\":\"address\"},{\"internalType\":\"uint8\",\"name\":\"_decimals\",\"type\":\"uint8\"},{\"internalType\":\"uint8\",\"name\":\"_hebeSwapDecimals\",\"type\":\"uint8\"},{\"internalType\":\"string\",\"name\":\"_baseToken\",\"type\":\"string\"},{\"internalType\":\"string\",\"name\":\"_quoteToken\",\"type\":\"string\"}],\"stateMutability\":\"nonpayable\",\"type\":\"constructor\"},{\"inputs\":[],\"name\":\"acceptTermsOfService\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"baseToken\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"quoteToken\",\"outputs\":[{\"internalType\":\"string\",\"name\":\"\",\"type\":\"string\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"readData\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"ref\",\"outputs\":[{\"internalType\":\"contract IStdReference\",\"name\":\"\",\"type\":\"address\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"scalingFactor\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/HebeSwapOracle.sol\":\"HebeSwapOracle\"},\"evmVersion\":\"london\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[\":@api3dao/=lib/contracts/\",\":@chainlink/contracts/=node_modules/@chainlink/contracts/\",\":@eth-optimism/=node_modules/@eth-optimism/\",\":@hebeswap/=lib/hebeswap-contract/\",\":@openzeppelin/=lib/openzeppelin-contracts/\",\":ds-test/=lib/forge-std/lib/ds-test/src/\",\":forge-std/=lib/forge-std/src/\",\":hebeswap-contract/=lib/hebeswap-contract/\",\":openzeppelin-contracts/=lib/openzeppelin-contracts/\",\":solmate/=lib/solmate/src/\"],\"viaIR\":true},\"sources\":{\"lib/hebeswap-contract/IStdReference.sol\":{\"keccak256\":\"0x805354452e33be1dfd58447a237b6bd506287bd30337543cc1e07e05601e4e18\",\"license\":\"Apache-2.0\",\"urls\":[\"bzz-raw://14662cd18e5e122d927e027d8f2ace81d298f5e9b26b84e07a42cd587711a271\",\"dweb:/ipfs/QmWRwfUpiGXspRSJboXBGXmMzzYbDkT2Hs276rRehbtAkT\"]},\"src/HebeSwapOracle.sol\":{\"keccak256\":\"0x24e9a24e8105104d57c6ad72be5bbfa8c7b9cdb77a27102453bd632aa79fbbea\",\"license\":\"AEL\",\"urls\":[\"bzz-raw://236777fe9d91c7e587a092ce6f2ffcdcadea603211a9327a854d81630a9ee824\",\"dweb:/ipfs/QmQrhn7fNXb2gHDk5YqNv3viTv24RgHqV9EsKWe9pD8kB7\"]},\"src/IOracle.sol\":{\"keccak256\":\"0xbdb82189368be9100ec49015ca5838207a3bc5bfec11543d0aede20811cb07ad\",\"license\":\"AEL\",\"urls\":[\"bzz-raw://d6f64b8238eaa188a9b9d7acac753ba0bfccc770b458be512c37c47bc8cafe4c\",\"dweb:/ipfs/QmWB2nD9chE3EAKYa4joucZUsFstZNJDjRoDbrdXEKkYk1\"]}},\"version\":1}","metadata":{"compiler":{"version":"0.8.13+commit.abaa5c0e"},"language":"Solidity","output":{"abi":[{"inputs":[{"internalType":"contract IStdReference","name":"_ref","type":"address"},{"internalType":"uint8","name":"_decimals","type":"uint8"},{"internalType":"uint8","name":"_hebeSwapDecimals","type":"uint8"},{"internalType":"string","name":"_baseToken","type":"string"},{"internalType":"string","name":"_quoteToken","type":"string"}],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"stateMutability":"nonpayable","type":"function","name":"acceptTermsOfService"},{"inputs":[],"stateMutability":"view","type":"function","name":"baseToken","outputs":[{"internalType":"string","name":"","type":"string"}]},{"inputs":[],"stateMutability":"view","type":"function","name":"quoteToken","outputs":[{"internalType":"string","name":"","type":"string"}]},{"inputs":[],"stateMutability":"view","type":"function","name":"readData","outputs":[{"internalType":"uint256","name":"","type":"uint256"}]},{"inputs":[],"stateMutability":"view","type":"function","name":"ref","outputs":[{"internalType":"contract IStdReference","name":"","type":"address"}]},{"inputs":[],"stateMutability":"view","type":"function","name":"scalingFactor","outputs":[{"internalType":"uint256","name":"","type":"uint256"}]}],"devdoc":{"kind":"dev","methods":{},"version":1},"userdoc":{"kind":"user","methods":{},"version":1}},"settings":{"remappings":["@api3dao/=lib/contracts/","@chainlink/contracts/=node_modules/@chainlink/contracts/","@eth-optimism/=node_modules/@eth-optimism/","@hebeswap/=lib/hebeswap-contract/","@openzeppelin/=lib/openzeppelin-contracts/","ds-test/=lib/forge-std/lib/ds-test/src/","forge-std/=lib/forge-std/src/","hebeswap-contract/=lib/hebeswap-contract/","openzeppelin-contracts/=lib/openzeppelin-contracts/","solmate/=lib/solmate/src/"],"optimizer":{"enabled":true,"runs":200},"metadata":{"bytecodeHash":"ipfs"},"compilationTarget":{"src/HebeSwapOracle.sol":"HebeSwapOracle"},"evmVersion":"london","libraries":{},"viaIR":true},"sources":{"lib/hebeswap-contract/IStdReference.sol":{"keccak256":"0x805354452e33be1dfd58447a237b6bd506287bd30337543cc1e07e05601e4e18","urls":["bzz-raw://14662cd18e5e122d927e027d8f2ace81d298f5e9b26b84e07a42cd587711a271","dweb:/ipfs/QmWRwfUpiGXspRSJboXBGXmMzzYbDkT2Hs276rRehbtAkT"],"license":"Apache-2.0"},"src/HebeSwapOracle.sol":{"keccak256":"0x24e9a24e8105104d57c6ad72be5bbfa8c7b9cdb77a27102453bd632aa79fbbea","urls":["bzz-raw://236777fe9d91c7e587a092ce6f2ffcdcadea603211a9327a854d81630a9ee824","dweb:/ipfs/QmQrhn7fNXb2gHDk5YqNv3viTv24RgHqV9EsKWe9pD8kB7"],"license":"AEL"},"src/IOracle.sol":{"keccak256":"0xbdb82189368be9100ec49015ca5838207a3bc5bfec11543d0aede20811cb07ad","urls":["bzz-raw://d6f64b8238eaa188a9b9d7acac753ba0bfccc770b458be512c37c47bc8cafe4c","dweb:/ipfs/QmWB2nD9chE3EAKYa4joucZUsFstZNJDjRoDbrdXEKkYk1"],"license":"AEL"}},"version":1},"id":2} \ No newline at end of file diff --git a/djed-sdk/src/djed/djed.js b/djed-sdk/src/djed/djed.js index 443c313..7ddfccb 100644 --- a/djed-sdk/src/djed/djed.js +++ b/djed-sdk/src/djed/djed.js @@ -1,4 +1,6 @@ import djedArtifact from "../artifacts/DjedABI.json"; +import djedIsisArtifact from "../artifacts/DjedIsisABI.json"; +import djedTefnutArtifact from "../artifacts/DjedTefnutABI.json"; import coinArtifact from "../artifacts/CoinABI.json"; import { convertInt, web3Promise } from "../helpers"; @@ -8,6 +10,16 @@ export const getDjedContract = (web3, DJED_ADDRESS) => { return djed; }; +export const getDjedIsisContract = (web3, DJED_ADDRESS) => { + const djed = new web3.eth.Contract(djedIsisArtifact.abi, DJED_ADDRESS); + return djed; +}; + +export const getDjedTefnutContract = (web3, DJED_ADDRESS) => { + const djed = new web3.eth.Contract(djedTefnutArtifact.abi, DJED_ADDRESS); + return djed; +}; + export const getCoinContracts = async (djedContract, web3) => { const [stableCoinAddress, reserveCoinAddress] = await Promise.all([ web3Promise(djedContract, "stableCoin"), @@ -27,3 +39,13 @@ export const getDecimals = async (stableCoin, reserveCoin) => { ]); return { scDecimals, rcDecimals }; }; + +export const checkIfShu = async (djedContract) => { + try { + // Check if scMaxPrice exists on the contract + await djedContract.methods.scMaxPrice(0).call(); + return true; + } catch (e) { + return false; + } +}; diff --git a/djed-sdk/src/djed/index.js b/djed-sdk/src/djed/index.js index f9686a0..a1cbb35 100644 --- a/djed-sdk/src/djed/index.js +++ b/djed-sdk/src/djed/index.js @@ -13,6 +13,19 @@ export { calculateFutureScPrice, } from "./stableCoin"; +export { + tradeDataPriceSellBoth, + sellBothTx, +} from "./sellBoth"; + +export { + buyScIsisTx, + sellScIsisTx, + buyRcIsisTx, + sellRcIsisTx, + sellBothIsisTx +} from "./isis"; + export { scalingFactor, FEE_UI_UNSCALED, @@ -29,6 +42,12 @@ export { getFees, } from "./tradeUtils"; -export { getDjedContract, getCoinContracts, getDecimals } from "./djed"; +export { getDjedContract, getDjedIsisContract, getDjedTefnutContract, getCoinContracts, getDecimals } from "./djed"; export { getCoinDetails, getSystemParams, getAccountDetails } from "./system"; +export { subscribeToDjedEvents, getPastDjedEvents } from "./listeners"; + +export { + approveTx, + checkAllowance, +} from "./token"; diff --git a/djed-sdk/src/djed/isis.js b/djed-sdk/src/djed/isis.js new file mode 100644 index 0000000..71e187d --- /dev/null +++ b/djed-sdk/src/djed/isis.js @@ -0,0 +1,82 @@ +import { FEE_UI_UNSCALED } from "./tradeUtils"; +import { buildTx } from "../helpers"; + +// # ISIS / TEFNUT Transaction Functions (ERC20 Base Asset) + +/** + * Buy StableCoins (Isis/Tefnut Variant - ERC20 Base Asset) + * Note: Caller must APPROVE the Djed contract to spend `amountBC` of the Base Asset before calling this. + * @param {object} djed The DjedContract instance + * @param {string} payer The address paying the Base Asset + * @param {string} receiver The address receiving the StableCoins + * @param {string} amountBC The amount of Base Asset to pay (in wei/smallest unit) + * @param {string} UI The UI address + * @param {string} DJED_ADDRESS The Djed contract address + * @returns {object} The transaction object + */ +export const buyScIsisTx = (djed, payer, receiver, amountBC, UI, DJED_ADDRESS) => { + // Signature: buyStableCoins(uint256 amountBC, address receiver, uint256 feeUI, address ui) + const data = djed.methods + .buyStableCoins(amountBC, receiver, FEE_UI_UNSCALED, UI) + .encodeABI(); + + // Value is 0 because Base Asset is ERC20 transferFrom, not msg.value + return buildTx(payer, DJED_ADDRESS, 0, data); +}; + +/** + * Sell StableCoins (Isis/Tefnut Variant) + * Note: Same logic as Osiris, but ensuring naming consistency if needed. + * But functionally, sellStableCoins signature is: sellStableCoins(uint256 amountSC, address receiver, uint256 feeUI, address ui) + * which matches Osiris. Using the same function is fine, but we provide an alias for clarity. + */ +export const sellScIsisTx = (djed, account, amountSC, UI, DJED_ADDRESS) => { + // Signature: sellStableCoins(uint256 amountSC, address receiver, uint256 feeUI, address ui) + // This is identical to Osiris, so we can reuse the logic or just wrap it. + // However, the internal implementation of Djed Isis would transfer ERC20 back to user. + const data = djed.methods + .sellStableCoins(amountSC, account, FEE_UI_UNSCALED, UI) + .encodeABI(); + return buildTx(account, DJED_ADDRESS, 0, data); +}; + +/** + * Buy ReserveCoins (Isis/Tefnut Variant - ERC20 Base Asset) + * Note: Caller must APPROVE the Djed contract to spend `amountBC` of the Base Asset before calling this. + * @param {object} djed The DjedContract instance + * @param {string} payer The address paying the Base Asset + * @param {string} receiver The address receiving the ReserveCoins + * @param {string} amountBC The amount of Base Asset to pay (in wei/smallest unit) + * @param {string} UI The UI address + * @param {string} DJED_ADDRESS The Djed contract address + * @returns {object} The transaction object + */ +export const buyRcIsisTx = (djed, payer, receiver, amountBC, UI, DJED_ADDRESS) => { + // Signature: buyReserveCoins(uint256 amountBC, address receiver, uint256 feeUI, address ui) + const data = djed.methods + .buyReserveCoins(amountBC, receiver, FEE_UI_UNSCALED, UI) + .encodeABI(); + + return buildTx(payer, DJED_ADDRESS, 0, data); + }; + +export const sellRcIsisTx = (djed, account, amountRC, UI, DJED_ADDRESS) => { + // Signature: sellReserveCoins(uint256 amountRC, address receiver, uint256 feeUI, address ui) + const data = djed.methods + .sellReserveCoins(amountRC, account, FEE_UI_UNSCALED, UI) + .encodeABI(); + return buildTx(account, DJED_ADDRESS, 0, data); +}; + +/** + * Sell Both Coins (Isis/Tefnut Variant) + * Note: Same logic as Osiris. + */ +export const sellBothIsisTx = (djed, account, amountSC, amountRC, UI, DJED_ADDRESS) => { + // Signature: sellBothCoins(uint256 amountSC, uint256 amountRC, address receiver, uint256 feeUI, address ui) + // Actually, check Djed.sol: sellBothCoins(uint256 amountSC, uint256 amountRC, address receiver, uint256 feeUI, address ui) + const data = djed.methods + .sellBothCoins(amountSC, amountRC, account, FEE_UI_UNSCALED, UI) + .encodeABI(); + return buildTx(account, DJED_ADDRESS, 0, data); +}; diff --git a/djed-sdk/src/djed/listeners.js b/djed-sdk/src/djed/listeners.js new file mode 100644 index 0000000..10d98d7 --- /dev/null +++ b/djed-sdk/src/djed/listeners.js @@ -0,0 +1,72 @@ +/** + * Utility to listen for Djed contract events + * @param {Object} djedContract - The Web3 contract instance + * @param {Object} callbacks - Object containing callback functions for different events + * @param {Function} callbacks.onBoughtStableCoins - (eventData) => {} + * @param {Function} callbacks.onSoldStableCoins - (eventData) => {} + * @param {Function} callbacks.onBoughtReserveCoins - (eventData) => {} + * @param {Function} callbacks.onSoldReserveCoins - (eventData) => {} + * @param {Function} callbacks.onSoldBothCoins - (eventData) => {} + * @param {Function} callbacks.onError - (error) => {} + */ +export const subscribeToDjedEvents = (djedContract, callbacks) => { + const events = [ + { name: "BoughtStableCoins", cb: callbacks.onBoughtStableCoins }, + { name: "SoldStableCoins", cb: callbacks.onSoldStableCoins }, + { name: "BoughtReserveCoins", cb: callbacks.onBoughtReserveCoins }, + { name: "SoldReserveCoins", cb: callbacks.onSoldReserveCoins }, + { name: "SoldBothCoins", cb: callbacks.onSoldBothCoins }, + ]; + + const subscriptions = []; + + events.forEach((event) => { + if (event.cb) { + const sub = djedContract.events[event.name]({ + fromBlock: "latest", + }) + .on("data", (data) => { + event.cb(data.returnValues); + }) + .on("error", (err) => { + if (callbacks.onError) callbacks.onError(err); + else console.error(`Error in ${event.name} subscription:`, err); + }); + subscriptions.push(sub); + } + }); + + return { + unsubscribe: () => { + subscriptions.forEach((sub) => { + if (sub.unsubscribe) sub.unsubscribe(); + }); + }, + }; +}; + +/** + * Utility to fetch past events from the Djed contract + * @param {Object} djedContract - The Web3 contract instance + * @param {string} eventName - Name of the event + * @param {Object} filter - Web3 filter object (e.g., { buyer: '0x...' }) + * @param {number|string} fromBlock - Starting block + * @returns {Promise} - Array of past events + */ +export const getPastDjedEvents = async ( + djedContract, + eventName, + filter = {}, + fromBlock = 0 +) => { + try { + return await djedContract.getPastEvents(eventName, { + filter, + fromBlock, + toBlock: "latest", + }); + } catch (error) { + console.error(`Error fetching past events for ${eventName}:`, error); + throw error; + } +}; diff --git a/djed-sdk/src/djed/reserveCoin.js b/djed-sdk/src/djed/reserveCoin.js index da2a6bc..43b58df 100644 --- a/djed-sdk/src/djed/reserveCoin.js +++ b/djed-sdk/src/djed/reserveCoin.js @@ -7,6 +7,7 @@ import { deductFees, FEE_UI_UNSCALED, tradeDataPriceCore, + getPriceMethod, } from "./tradeUtils"; /** @@ -18,6 +19,7 @@ import { */ export const tradeDataPriceBuyRc = async (djed, rcDecimals, amountScaled) => { try { + const scMethod = await getPriceMethod(djed, 'buyRC'); const data = await tradeDataPriceCore( djed, "rcBuyingPrice", @@ -44,6 +46,7 @@ export const tradeDataPriceBuyRc = async (djed, rcDecimals, amountScaled) => { export const tradeDataPriceSellRc = async (djed, rcDecimals, amountScaled) => { try { + const scMethod = await getPriceMethod(djed, 'sellRC'); const data = await tradeDataPriceCore( djed, "rcTargetPrice", diff --git a/djed-sdk/src/djed/sellBoth.js b/djed-sdk/src/djed/sellBoth.js new file mode 100644 index 0000000..ce10415 --- /dev/null +++ b/djed-sdk/src/djed/sellBoth.js @@ -0,0 +1,96 @@ +import { BC_DECIMALS } from "../constants"; +import { + decimalScaling, + decimalUnscaling, + buildTx, + web3Promise, + scaledUnscaledPromise, +} from "../helpers"; +import { + getFees, + convertToBC, + deductFees, + FEE_UI_UNSCALED, + getPriceMethod, +} from "./tradeUtils"; + +/** + * Function that calculates fees and how much BC (totalBCAmount) user will receive if he sells desired amount of stable coin and reserve coin + * @param {*} djed DjedContract + * @param {*} scDecimals Stable coin decimals + * @param {*} rcDecimals Reserve coin decimals + * @param {*} amountScScaled Stable coin amount that user wants to sell + * @param {*} amountRcScaled Reserve coin amount that user wants to sell + * @returns + */ +export const tradeDataPriceSellBoth = async ( + djed, + scDecimals, + rcDecimals, + amountScScaled, + amountRcScaled +) => { + try { + const scPriceMethod = await getPriceMethod(djed, 'sellSC'); + const [scPriceData, rcPriceData] = await Promise.all([ + scaledUnscaledPromise(web3Promise(djed, scPriceMethod, 0), BC_DECIMALS), + scaledUnscaledPromise(web3Promise(djed, "rcTargetPrice", 0), BC_DECIMALS), + ]); + + const amountScUnscaled = decimalUnscaling(amountScScaled, scDecimals); + const amountRcUnscaled = decimalUnscaling(amountRcScaled, rcDecimals); + + const scValueBC = convertToBC( + amountScUnscaled, + scPriceData[1], + scDecimals + ); + const rcValueBC = convertToBC( + amountRcUnscaled, + rcPriceData[1], + rcDecimals + ); + + const totalValueBC = (scValueBC + rcValueBC).toString(); + + const { treasuryFee, fee } = await getFees(djed); + const totalBCAmount = deductFees(totalValueBC, fee, treasuryFee); + + return { + scPriceScaled: scPriceData[0], + scPriceUnscaled: scPriceData[1], + rcPriceScaled: rcPriceData[0], + rcPriceUnscaled: rcPriceData[1], + amountScUnscaled, + amountRcUnscaled, + totalBCScaled: decimalScaling(totalBCAmount.toString(), BC_DECIMALS), + totalBCUnscaled: totalBCAmount.toString(), + }; + } catch (error) { + console.error("Error in tradeDataPriceSellBoth:", error); + } +}; + +/** + * Function to sell both stablecoins and reservecoins + * @param {*} djed DjedContract + * @param {*} account User address + * @param {*} amountSC Unscaled amount of stablecoins to sell + * @param {*} amountRC Unscaled amount of reservecoins to sell + * @param {*} UI UI address for fee + * @param {*} DJED_ADDRESS Address of Djed contract + * @returns + */ +export const sellBothTx = ( + djed, + account, + amountSC, + amountRC, + UI, + DJED_ADDRESS +) => { + const data = djed.methods + .sellBothCoins(amountSC, amountRC, account, FEE_UI_UNSCALED, UI) + .encodeABI(); + return buildTx(account, DJED_ADDRESS, 0, data); +}; diff --git a/djed-sdk/src/djed/stableCoin.js b/djed-sdk/src/djed/stableCoin.js index f845772..eaa85dd 100644 --- a/djed-sdk/src/djed/stableCoin.js +++ b/djed-sdk/src/djed/stableCoin.js @@ -7,6 +7,7 @@ import { convertToBC, deductFees, FEE_UI_UNSCALED, + getPriceMethod, } from "./tradeUtils"; /** @@ -18,9 +19,10 @@ import { */ export const tradeDataPriceBuySc = async (djed, scDecimals, amountScaled) => { try { + const method = await getPriceMethod(djed, 'buySC'); const data = await tradeDataPriceCore( djed, - "scPrice", + method, scDecimals, amountScaled ); @@ -51,9 +53,10 @@ export const tradeDataPriceBuySc = async (djed, scDecimals, amountScaled) => { */ export const tradeDataPriceSellSc = async (djed, scDecimals, amountScaled) => { try { + const method = await getPriceMethod(djed, 'sellSC'); const data = await tradeDataPriceCore( djed, - "scPrice", + method, scDecimals, amountScaled ); diff --git a/djed-sdk/src/djed/system.js b/djed-sdk/src/djed/system.js index 90d33e2..2b4ca1b 100644 --- a/djed-sdk/src/djed/system.js +++ b/djed-sdk/src/djed/system.js @@ -7,6 +7,7 @@ import { decimalScaling, percentageScale, } from "../helpers"; +import { checkIfShu } from "./djed"; export const getCoinDetails = async ( stableCoin, @@ -16,6 +17,9 @@ export const getCoinDetails = async ( rcDecimals ) => { try { + const isShu = await checkIfShu(djed); + const priceMethod = isShu ? "scMaxPrice" : "scPrice"; + const [ [scaledNumberSc, unscaledNumberSc], [scaledPriceSc, unscaledPriceSc], @@ -25,14 +29,14 @@ export const getCoinDetails = async ( scaledScExchangeRate, ] = await Promise.all([ scaledUnscaledPromise(web3Promise(stableCoin, "totalSupply"), scDecimals), - scaledUnscaledPromise(web3Promise(djed, "scPrice", 0), BC_DECIMALS), + scaledUnscaledPromise(web3Promise(djed, priceMethod, 0), BC_DECIMALS), scaledUnscaledPromise( web3Promise(reserveCoin, "totalSupply"), rcDecimals ), scaledUnscaledPromise(web3Promise(djed, "R", 0), BC_DECIMALS), scaledPromise(web3Promise(djed, "rcBuyingPrice", 0), BC_DECIMALS), - scaledPromise(web3Promise(djed, "scPrice", 0), BC_DECIMALS), + scaledPromise(web3Promise(djed, priceMethod, 0), BC_DECIMALS), ]); // Define default empty value @@ -40,6 +44,8 @@ export const getCoinDetails = async ( let scaledSellPriceRc = emptyValue; let unscaledSellPriceRc = emptyValue; let percentReserveRatio = emptyValue; + let percentReserveRatioMin = emptyValue; + let percentReserveRatioMax = emptyValue; // Check total reserve coin supply to calculate sell price if (BigInt(unscaledNumberRc) !== 0n) { @@ -51,14 +57,25 @@ export const getCoinDetails = async ( // Check total stable coin supply to calculate reserve ratio if (BigInt(unscaledNumberSc) !== 0n) { - percentReserveRatio = await percentScaledPromise( - web3Promise(djed, "ratio"), - SCALING_DECIMALS - ); + if (isShu) { + const [ratioMin, ratioMax] = await Promise.all([ + percentScaledPromise(web3Promise(djed, "ratioMin"), SCALING_DECIMALS), + percentScaledPromise(web3Promise(djed, "ratioMax"), SCALING_DECIMALS) + ]); + percentReserveRatioMin = ratioMin; + percentReserveRatioMax = ratioMax; + percentReserveRatio = `${ratioMin} - ${ratioMax}`; + } else { + percentReserveRatio = await percentScaledPromise( + web3Promise(djed, "ratio"), + SCALING_DECIMALS + ); + } } // Return the results return { + isShu, scaledNumberSc, unscaledNumberSc, scaledPriceSc, @@ -68,6 +85,8 @@ export const getCoinDetails = async ( scaledReserveBc, unscaledReserveBc, percentReserveRatio, + percentReserveRatioMin, + percentReserveRatioMax, scaledBuyPriceRc, scaledSellPriceRc, unscaledSellPriceRc, @@ -86,12 +105,22 @@ export const getSystemParams = async (djed) => { feeUnscaled, treasuryFee, thresholdSupplySC, + initialTreasuryFee, + treasuryRevenueTarget, + treasuryRevenue, + rcMinPrice, + txLimit, ] = await Promise.all([ web3Promise(djed, "reserveRatioMin"), web3Promise(djed, "reserveRatioMax"), web3Promise(djed, "fee"), percentScaledPromise(web3Promise(djed, "treasuryFee"), SCALING_DECIMALS), web3Promise(djed, "thresholdSupplySC"), + web3Promise(djed, "initialTreasuryFee"), + web3Promise(djed, "treasuryRevenueTarget"), + web3Promise(djed, "treasuryRevenue"), + web3Promise(djed, "rcMinPrice"), + web3Promise(djed, "txLimit"), ]); return { @@ -111,6 +140,12 @@ export const getSystemParams = async (djed) => { feeUnscaled, treasuryFee, thresholdSupplySC, + initialTreasuryFee: percentageScale(initialTreasuryFee, SCALING_DECIMALS, true), + initialTreasuryFeeUnscaled: initialTreasuryFee, + treasuryRevenueTarget, + treasuryRevenue, + rcMinPrice, + txLimit, }; }; diff --git a/djed-sdk/src/djed/token.js b/djed-sdk/src/djed/token.js new file mode 100644 index 0000000..85f11e6 --- /dev/null +++ b/djed-sdk/src/djed/token.js @@ -0,0 +1,10 @@ +import { buildTx } from "../helpers"; + +export const approveTx = (tokenContract, owner, spender, amount) => { + const data = tokenContract.methods.approve(spender, amount).encodeABI(); + return buildTx(owner, tokenContract.options.address, 0, data); +}; + +export const checkAllowance = async (tokenContract, owner, spender) => { + return await tokenContract.methods.allowance(owner, spender).call(); +}; diff --git a/djed-sdk/src/djed/tradeUtils.js b/djed-sdk/src/djed/tradeUtils.js index 456f1f1..5c10d1c 100644 --- a/djed-sdk/src/djed/tradeUtils.js +++ b/djed-sdk/src/djed/tradeUtils.js @@ -112,10 +112,11 @@ export const calculateIsRatioAboveMin = ({ * @param {*} amountUSD * @param {*} totalSCSupply * @param {*} thresholdSCSupply + * @param {*} txLimit * @returns */ -export const isTxLimitReached = (amountUSD, totalSCSupply, thresholdSCSupply) => - amountUSD > TRANSACTION_USD_LIMIT && +export const isTxLimitReached = (amountUSD, totalSCSupply, thresholdSCSupply, txLimit) => + (BigInt(amountUSD) > BigInt(txLimit || TRANSACTION_USD_LIMIT)) && BigInt(totalSCSupply) >= BigInt(thresholdSCSupply); export const promiseTx = (isWalletConnected, tx, signer) => { @@ -202,3 +203,23 @@ export const getFees = async (djed) => { console.log("error", error); } }; + +/** + * Function that returns the correct price method name based on the contract version and operation + * @param {*} djed Djed contract + * @param {*} operation 'buySC', 'sellSC', 'buyRC', 'sellRC' + * @returns + */ +export const getPriceMethod = async (djed, operation) => { + const isShu = await djed.methods.scMaxPrice(0).call().then(() => true).catch(() => false); + + if (!isShu) return "scPrice"; + + switch (operation) { + case 'buySC': return "scMaxPrice"; + case 'sellSC': return "scMinPrice"; + case 'buyRC': return "scMinPrice"; + case 'sellRC': return "scMaxPrice"; + default: return "scPrice"; + } +}; diff --git a/djed-sdk/src/oracle/index.js b/djed-sdk/src/oracle/index.js index a956ec5..6c94d92 100644 --- a/djed-sdk/src/oracle/index.js +++ b/djed-sdk/src/oracle/index.js @@ -1 +1 @@ -export { getOracleAddress, getOracleContract } from "./oracle"; \ No newline at end of file +export { getOracleAddress, getOracleContract, getHebeSwapOracleContract, getChainlinkOracleContract, getAPI3OracleContract } from "./oracle"; \ No newline at end of file diff --git a/djed-sdk/src/oracle/oracle.js b/djed-sdk/src/oracle/oracle.js index 54644e0..7d53d02 100644 --- a/djed-sdk/src/oracle/oracle.js +++ b/djed-sdk/src/oracle/oracle.js @@ -1,5 +1,8 @@ import { convertInt,web3Promise } from "../helpers"; import oracleArtifact from "../artifacts/OracleABI.json"; +import hebeSwapOracleArtifact from "../artifacts/HebeSwapOracleABI.json"; +import chainlinkOracleArtifact from "../artifacts/ChainlinkOracleABI.json"; +import api3OracleArtifact from "../artifacts/API3OracleABI.json"; export const getOracleAddress = async (djedContract) => { return await web3Promise(djedContract, "oracle"); @@ -11,3 +14,25 @@ export const getOracleContract = (web3, oracleAddress, msgSender) => { }); return oracle; }; + +export const getHebeSwapOracleContract = (web3, oracleAddress, msgSender) => { + const oracle = new web3.eth.Contract(hebeSwapOracleArtifact.abi, oracleAddress, { + from: msgSender + }); + return oracle; +}; + +export const getChainlinkOracleContract = (web3, oracleAddress, msgSender) => { + const oracle = new web3.eth.Contract(chainlinkOracleArtifact.abi, oracleAddress, { + from: msgSender + }); + return oracle; +}; + + +export const getAPI3OracleContract = (web3, oracleAddress, msgSender) => { + const oracle = new web3.eth.Contract(api3OracleArtifact.abi, oracleAddress, { + from: msgSender + }); + return oracle; +}; diff --git a/stablepay-sdk/dist/esm/index.js b/stablepay-sdk/dist/esm/index.js index 907d446..dec7d9e 100644 --- a/stablepay-sdk/dist/esm/index.js +++ b/stablepay-sdk/dist/esm/index.js @@ -1 +1 @@ -import{getWeb3 as e,getDjedContract as t,getCoinContracts as n,getDecimals as r,getOracleAddress as a,getOracleContract as o,tradeDataPriceBuySc as i,buyScTx as s}from"djed-sdk";import c,{useContext as l,createContext as d,useState as m,useEffect as u,useRef as h,useCallback as w}from"react";import{defineChain as k,createWalletClient as g,custom as C,createPublicClient as p,http as b,parseEther as f,parseUnits as v,encodeFunctionData as E}from"viem";import{sepolia as y}from"viem/chains";const _={sepolia:{uri:"https://ethereum-sepolia.publicnode.com/",chainId:11155111,djedAddress:"0x624FcD0a1F9B5820c950FefD48087531d38387f4",tokens:{stablecoin:{symbol:"SOD",address:"0x6b930182787F346F18666D167e8d32166dC5eFBD",decimals:18,isDirectTransfer:!0},native:{symbol:"ETH",decimals:18,isNative:!0}},feeUI:0},"milkomeda-mainnet":{uri:"https://rpc-mainnet-cardano-evm.c1.milkomeda.com",chainId:2001,djedAddress:"0x67A30B399F5Ed499C1a6Bc0358FA6e42Ea4BCe76",tokens:{stablecoin:{symbol:"MOD",address:"0xcbA90fB1003b9D1bc6a2b66257D2585011b004e9",decimals:18,isDirectTransfer:!0},native:{symbol:"mADA",decimals:18,isNative:!0}},feeUI:0},"ethereum-classic":{uri:"https://etc.rivet.link",chainId:61,djedAddress:"0xCc3664d7021FD36B1Fe2b136e2324710c8442cCf",tokens:{stablecoin:{symbol:"ECSD",address:"0x5A7Ca94F6E969C94bef4CE5e2f90ed9d4891918A",decimals:18,isDirectTransfer:!0},native:{symbol:"ETC",decimals:18,isNative:!0}},feeUI:0}};class N{constructor(e,t){this.networkUri=e,this.djedAddress=t}async init(){if(!this.networkUri||!this.djedAddress)throw new Error("Network URI and DJED address are required");try{this.web3=await e(this.networkUri),this.djedContract=t(this.web3,this.djedAddress);try{const{stableCoin:e,reserveCoin:t}=await n(this.djedContract,this.web3),{scDecimals:i,rcDecimals:s}=await r(e,t);this.stableCoin=e,this.reserveCoin=t,this.scDecimals=i,this.rcDecimals=s,this.oracleContract=await a(this.djedContract).then((e=>o(this.web3,e,this.djedContract._address))),this.oracleAddress=this.oracleContract._address}catch(e){if(console.error("[Transaction] Error fetching contract details:",e),e.message&&e.message.includes("execution reverted")){const e=e=>e.includes("milkomeda")?{name:"Milkomeda",chainId:"2001"}:e.includes("mordor")?{name:"Mordor Testnet",chainId:"63"}:e.includes("sepolia")?{name:"Sepolia",chainId:"11155111"}:e.includes("etc.rivet.link")?{name:"Ethereum Classic",chainId:"61"}:{name:"the selected network",chainId:"unknown"},{name:t,chainId:n}=e(this.networkUri);throw new Error(`Failed to interact with Djed contract at ${this.djedAddress} on ${t}.\n\nPossible causes:\n- The contract address may be incorrect\n- The contract may not be deployed on ${t}\n- The contract may not be a valid Djed contract\n\nPlease verify the contract address is correct for ${t} (Chain ID: ${n}).`)}throw e}}catch(e){if(console.error("[Transaction] Error initializing transaction:",e),e.message&&(e.message.includes("CONNECTION ERROR")||e.message.includes("ERR_NAME_NOT_RESOLVED"))){const e=(e=>e.includes("milkomeda")?"Milkomeda":e.includes("mordor")?"Mordor":e.includes("sepolia")?"Sepolia":"the selected network")(this.networkUri);throw new Error(`Failed to connect to ${e} RPC endpoint: ${this.networkUri}\n\nPossible causes:\n- The RPC endpoint may be temporarily unavailable\n- DNS resolution issue (check your internet connection)\n- Network firewall blocking the connection\n\nPlease try again in a few moments or check the network status.`)}throw e}}getBlockchainDetails(){return{web3Available:!!this.web3,djedContractAvailable:!!this.djedContract,stableCoinAddress:this.stableCoin?this.stableCoin._address:"N/A",reserveCoinAddress:this.reserveCoin?this.reserveCoin._address:"N/A",stableCoinDecimals:this.scDecimals,reserveCoinDecimals:this.rcDecimals,oracleAddress:this.oracleAddress||"N/A",oracleContractAvailable:!!this.oracleContract}}async handleTradeDataBuySc(e){if(!this.djedContract)throw new Error("DJED contract is not initialized");if("string"!=typeof e)throw new Error("Amount must be a string");try{return(await i(this.djedContract,this.scDecimals,e)).totalBCScaled}catch(e){throw console.error("Error fetching trade data for buying stablecoins: ",e),e}}async buyStablecoins(e,t,n){if(!this.djedContract)throw new Error("DJED contract is not initialized");try{const r="0x0232556C83791b8291E9b23BfEa7d67405Bd9839";return await s(this.djedContract,e,t,n,r,this.djedAddress)}catch(e){throw console.error("Error executing buyStablecoins transaction: ",e),e}}}var T="main_stablePayButton__UA7HC",S="main_logo__ITyEy",A="main_buttonText__N-ewy";const D=({onClick:e,size:t="medium"})=>{const n={small:{width:"200px",height:"50px",fontSize:"14px"},medium:{width:"250px",height:"60px",fontSize:"16px"},large:{width:"300px",height:"70px",fontSize:"18px"}},r={small:{width:"35px",height:"33px"},medium:{width:"40px",height:"38px"},large:{width:"45px",height:"43px"}},a=n[t]||n.medium,o=r[t]||r.medium;return c.createElement("button",{className:T,onClick:e,style:a},c.createElement("div",{className:S,style:o}),c.createElement("span",{className:A},"Pay with StablePay"))};var x={dialogOverlay:"PricingCard_dialogOverlay__0XJrE",pricingCard:"PricingCard_pricingCard__LrWb9",small:"PricingCard_small__J4CHj",medium:"PricingCard_medium__EVmTB",large:"PricingCard_large__A6pnX",dialogClose:"PricingCard_dialogClose__jJ1tM",pricingCardHeader:"PricingCard_pricingCardHeader__wGczA",allianceLogo:"PricingCard_allianceLogo__URa-U",stablepayTitle:"PricingCard_stablepayTitle__4t848",pricingCardBody:"PricingCard_pricingCardBody__0wKQn",selectField:"PricingCard_selectField__LBPoZ",transactionReview:"PricingCard_transactionReview__Ix-eL",transactionInfo:"PricingCard_transactionInfo__Ck-Rc",transactionLabel:"PricingCard_transactionLabel__GDux7",transactionValue:"PricingCard_transactionValue__q-xxp",infoSection:"PricingCard_infoSection__gyjMQ",infoIcon:"PricingCard_infoIcon__rraxD",infoText:"PricingCard_infoText__l4b7A",walletButton:"PricingCard_walletButton__llw4v",loading:"PricingCard_loading__2-tGA",error:"PricingCard_error__m5fK-",networkError:"PricingCard_networkError__zR-36",errorText:"PricingCard_errorText__qZRJt","message-box":"PricingCard_message-box__vkUKy",detailsButton:"PricingCard_detailsButton__jHglL",errorDetails:"PricingCard_errorDetails__CzN-7",loadingContainer:"PricingCard_loadingContainer__6nOVa",spinner:"PricingCard_spinner__9ucQv",spin:"PricingCard_spin__24tni"};const P=({children:e,onClose:t,size:n="medium"})=>c.createElement("div",{className:x.dialogOverlay},c.createElement("div",{className:`${x.pricingCard} ${x[n]}`},c.createElement("button",{className:x.dialogClose,onClick:t},"×"),c.createElement("div",{className:x.pricingCardHeader},c.createElement("div",{className:x.allianceLogo}),c.createElement("h2",{className:x.stablepayTitle},"StablePay")),c.createElement("div",{className:x.pricingCardBody},e)));class I{constructor(e){this.networkSelector=e,this.selectedToken=null}selectToken(e){const t=this.networkSelector.getSelectedNetworkConfig();return!(!t||!t.tokens[e])&&(this.selectedToken={key:e,...t.tokens[e]},!0)}getSelectedToken(){return this.selectedToken}getAvailableTokens(){const e=this.networkSelector.getSelectedNetworkConfig();return e?Object.entries(e.tokens).map((([e,t])=>({key:e,...t}))):[]}resetSelection(){this.selectedToken=null}}const B=d(),M=({children:e,networkSelector:t})=>{const[n]=m((()=>new I(t))),[r,a]=m(null),[o,i]=m(null),[s,l]=m(null),d=()=>{i(null),l(null)};return u((()=>{a(t.selectedNetwork)}),[t.selectedNetwork]),c.createElement(B.Provider,{value:{networkSelector:t,tokenSelector:n,selectedNetwork:r,selectedToken:o,transactionDetails:s,setTransactionDetails:l,selectNetwork:e=>!!t.selectNetwork(e)&&(a(e),d(),!0),selectToken:e=>{if(n.selectToken(e)){const e=n.getSelectedToken();return i(e),!0}return!1},resetSelections:()=>{t.selectNetwork(null),a(null),d()}}},e)},$=()=>{const e=l(B);if(void 0===e)throw new Error("useNetwork must be used within a NetworkProvider");return e},j=()=>{const{networkSelector:e,selectedNetwork:t,selectNetwork:n}=$();return c.createElement("div",{className:x.selectField},c.createElement("label",{htmlFor:"network-select"},"Select Network"),c.createElement("select",{id:"network-select",onChange:e=>{n(e.target.value)},value:t||""},c.createElement("option",{value:"",disabled:!0},"Select a network"),Object.keys(e.availableNetworks).map((e=>c.createElement("option",{key:e,value:e},e)))))},U=()=>{const{networkSelector:e,tokenSelector:t,selectedNetwork:n,selectedToken:r,selectToken:a,setTransactionDetails:o}=$(),[i,s]=m(!1),[l,d]=m(null),u=n?t.getAvailableTokens():[];return c.createElement("div",{className:x.selectField},c.createElement("label",{htmlFor:"token-select"},"Select Token"),c.createElement("select",{id:"token-select",onChange:async r=>{const i=r.target.value;d(null),s(!0);try{if(a(i)){const r=e.getSelectedNetworkConfig(),a=new N(r.uri,r.djedAddress);await a.init();const s=e.getTokenAmount(i),c=a.getBlockchainDetails();let l=null;"native"===i&&(l=await a.handleTradeDataBuySc(String(s))),o({network:n,token:i,tokenSymbol:t.getSelectedToken().symbol,amount:s,receivingAddress:e.getReceivingAddress(),djedContractAddress:r.djedAddress,isDirectTransfer:t.getSelectedToken().isDirectTransfer||!1,isNativeToken:t.getSelectedToken().isNative||!1,tradeAmount:l?l.amount:null,...c})}}catch(e){console.error("Error fetching transaction details:",e),d("Failed to fetch transaction details. Please try again.")}finally{s(!1)}},value:r?r.key:"",disabled:!n||i},c.createElement("option",{value:"",disabled:!0},n?i?"Loading...":"Select a token":"Please select a network first"),u.map((e=>c.createElement("option",{key:e.key,value:e.key},e.symbol," (",e.isDirectTransfer?"Direct Transfer":"Native",")")))),l&&c.createElement("div",{className:x.error},l))};k({id:63,name:"Mordor Testnet",network:"mordor",nativeCurrency:{decimals:18,name:"Mordor Ether",symbol:"METC"},rpcUrls:{default:{http:["https://rpc.mordor.etccooperative.org"],webSocket:["wss://rpc.mordor.etccooperative.org/ws"]}},blockExplorers:{default:{name:"BlockScout",url:"https://blockscout.com/etc/mordor"}},testnet:!0});const F=k({id:2001,name:"Milkomeda C1 Mainnet",network:"milkomeda",nativeCurrency:{decimals:18,name:"Milkomeda ADA",symbol:"mADA"},rpcUrls:{default:{http:["https://rpc-mainnet-cardano-evm.c1.milkomeda.com"]}},blockExplorers:{default:{name:"Milkomeda Explorer",url:"https://explorer-mainnet-cardano-evm.c1.milkomeda.com"}},testnet:!1}),R=k({id:61,name:"Ethereum Classic",network:"etc",nativeCurrency:{decimals:18,name:"Ethereum Classic",symbol:"ETC"},rpcUrls:{default:{http:["https://etc.rivet.link"]}},blockExplorers:{default:{name:"Blockscout",url:"https://blockscout.com/etc/mainnet"}},testnet:!1}),L=d(null),z=async e=>{if(!window.ethereum)throw new Error("MetaMask not installed");const t=(e=>{switch(e){case"sepolia":return{chainId:`0x${y.id.toString(16)}`,chainName:"Sepolia",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:y.rpcUrls.default.http,blockExplorerUrls:y.blockExplorers?.default?.url?[y.blockExplorers.default.url]:[]};case"ethereum-classic":return{chainId:`0x${R.id.toString(16)}`,chainName:"Ethereum Classic",nativeCurrency:{name:"Ethereum Classic",symbol:"ETC",decimals:18},rpcUrls:["https://etc.rivet.link"],blockExplorerUrls:["https://blockscout.com/etc/mainnet"]};case"milkomeda-mainnet":return{chainId:`0x${F.id.toString(16)}`,chainName:"Milkomeda C1 Mainnet",nativeCurrency:{name:"Milkomeda ADA",symbol:"mADA",decimals:18},rpcUrls:["https://rpc-mainnet-cardano-evm.c1.milkomeda.com"],blockExplorerUrls:["https://explorer-mainnet-cardano-evm.c1.milkomeda.com"]};default:return null}})(e);if(!t)throw new Error(`Unsupported network: ${e}`);try{await window.ethereum.request({method:"wallet_switchEthereumChain",params:[{chainId:t.chainId}]})}catch(e){if(4902!==e.code)throw 4001===e.code?new Error(`User rejected switching to ${t.chainName}. Please switch manually in MetaMask.`):new Error(`Failed to switch to ${t.chainName}: ${e.message}`);try{await window.ethereum.request({method:"wallet_addEthereumChain",params:[t]})}catch(e){if(4001===e.code)throw new Error(`User rejected adding ${t.chainName} to MetaMask. Please add it manually.`);throw new Error(`Failed to add ${t.chainName} to MetaMask: ${e.message}`)}}},W=({children:e})=>{const{selectedNetwork:t}=$(),[n,r]=m(null),[a,o]=m(null),[i,s]=m(null),[l,d]=m(null),[k,f]=m(null),[v,E]=m(null),[_,N]=m(!1),T=t?(e=>{switch(e){case"sepolia":return y;case"ethereum-classic":return R;case"milkomeda-mainnet":return F;default:return null}})(t):null,S=T?T.id:null,A=h(null),D=h(null),x=w((()=>{r(null),o(null),s(null),d(null),f(null),E(null)}),[]),P=w((async e=>{const n=parseInt(e,16);if(d(n),T&&n===S){if(E(null),window.ethereum&&T){const e=g({chain:T,transport:C(window.ethereum)});r(e)}}else if(T&&n!==S){E(`Wrong network detected. Please switch to ${T?.name||t||"selected network"}`)}}),[T,S,t]);D.current=P;const I=w((async e=>{if(0===e.length){if(x(),window.ethereum){const e=A.current,t=D.current;e&&window.ethereum.removeListener("accountsChanged",e),t&&window.ethereum.removeListener("chainChanged",t)}}else if(s(e[0]),T)try{const t=p({chain:T,transport:b()});o(t);const n=await t.getBalance({address:e[0]});f(parseFloat(n)/Math.pow(10,18))}catch(e){console.error("Error fetching balance:",e),f(null)}}),[T,x]);A.current=I;const B=w((()=>{if(x(),window.ethereum){const e=A.current,t=D.current;e&&window.ethereum.removeListener("accountsChanged",e),t&&window.ethereum.removeListener("chainChanged",t)}}),[x]),M=w((()=>{T&&o(p({chain:T,transport:b()}))}),[T]),j=w((async()=>{if(!window.ethereum)return E("Please install MetaMask or another Web3 wallet"),!1;if(!t||!T)return E("Please select a network first"),!1;N(!0),E(null);try{const e=await window.ethereum.request({method:"eth_requestAccounts"});if(0===e.length)throw new Error("No wallet address found. Please unlock your wallet.");const n=await window.ethereum.request({method:"eth_chainId"});parseInt(n,16)!==S&&await z(t);const a=g({chain:T,transport:C(window.ethereum)});r(a),s(e[0]),d(S);const i=p({chain:T,transport:b()});o(i);try{const t=await i.getBalance({address:e[0]});f(parseFloat(t)/Math.pow(10,18))}catch(e){console.error("Error fetching balance:",e),f(null)}return A.current=I,D.current=P,window.ethereum.on("accountsChanged",I),window.ethereum.on("chainChanged",P),!0}catch(e){return console.error("Error connecting wallet:",e),E(e.message),!1}finally{N(!1)}}),[t,T,S,I,P]),U=w((async()=>{if(!(window.ethereum&&t&&T&&i)){return E("Wallet not connected or network not selected"),null}try{const e=await window.ethereum.request({method:"eth_chainId"});if(parseInt(e,16)!==S){E(null),await z(t);const e=500;await new Promise((t=>setTimeout(t,e)));const n=await window.ethereum.request({method:"eth_chainId"}),r=parseInt(n,16);if(r!==S)throw new Error(`Failed to switch network. MetaMask is still on chain ${r}, expected ${S}`)}const n=g({chain:T,transport:C(window.ethereum)});return r(n),d(S),E(null),n}catch(e){return E(e.message),null}}),[t,T,S,i]),W=h(t);return u((()=>{if(null!==W.current&&W.current!==t&&i&&(x(),window.ethereum)){const e=A.current,t=D.current;e&&window.ethereum.removeListener("accountsChanged",e),t&&window.ethereum.removeListener("chainChanged",t)}W.current=t}),[t,i,x]),u((()=>{M()}),[M]),c.createElement(L.Provider,{value:{walletClient:n,publicClient:a,account:i,chainId:l,balance:k,error:v,isConnecting:_,connectWallet:j,disconnectWallet:B,ensureCorrectNetwork:U,expectedChainId:S}},e)},O=({onTransactionComplete:e})=>{const{networkSelector:t,selectedNetwork:n,selectedToken:r,transactionDetails:a,setTransactionDetails:o}=$(),{connectWallet:i,account:s,walletClient:d,publicClient:h,isConnecting:w,ensureCorrectNetwork:k,expectedChainId:g}=(()=>{const e=l(L);if(!e)throw new Error("useWallet must be used within a WalletProvider");return e})(),[C,p]=m(null),[b,y]=m(null),[_,T]=m(null),[S,A]=m(""),[D,P]=m(null),[I,B]=m(null),[M,j]=m(!1);if(u((()=>{T(null),y(null),A(""),B(null),P(null)}),[n,r]),u((()=>{(async()=>{if(n&&r)try{const e=t.getSelectedNetworkConfig(),a=t.getReceivingAddress(),i=t.getTokenAmount(r.key),s=new N(e.uri,e.djedAddress);await s.init(),p(s);let c=null;if("native"===r.key)try{c=await s.handleTradeDataBuySc(String(i)),y(c)}catch(e){console.error("Error fetching trade data:",e)}o({network:n,token:r.key,tokenSymbol:r.symbol,amount:i||"0",receivingAddress:a,djedContractAddress:e.djedAddress,isDirectTransfer:r.isDirectTransfer||!1,isNativeToken:r.isNative||!1,tradeAmount:c?c.amount:null,...s.getBlockchainDetails()})}catch(e){console.error("Error initializing transaction:",e)}})()}),[n,r,t,o]),!a)return c.createElement("div",{className:x.loading},"Initializing transaction...");const U=()=>{if(!D||!n)return null;const e={"ethereum-classic":"https://blockscout.com/etc/mainnet/tx/",sepolia:"https://sepolia.etherscan.io/tx/","milkomeda-mainnet":"https://explorer-mainnet-cardano-evm.c1.milkomeda.com/tx/"};return e[n]?`${e[n]}${D}`:null};return c.createElement("div",{className:x.transactionReview},c.createElement("div",{className:x.transactionInfo},c.createElement("span",{className:x.transactionLabel},"Network:"),c.createElement("span",{className:x.transactionValue},a.network)),c.createElement("div",{className:x.transactionInfo},c.createElement("span",{className:x.transactionLabel},"You Pay:"),c.createElement("span",{className:x.transactionValue},"stablecoin"===r.key?`${a.amount} ${a.tokenSymbol}`:`${b||"Calculating..."} ${a.tokenSymbol}`)),c.createElement("button",{className:x.walletButton,onClick:async()=>{await i()},disabled:w},w?"Connecting...":"Connect Wallet"),s&&!_&&c.createElement("button",{className:x.walletButton,onClick:async()=>{if(s&&a&&C)try{T(null),B(null),A("⏳ Preparing transaction...");const e=a.receivingAddress;let n;if("native"===r.key){const t="0x0232556C83791b8291E9b23BfEa7d67405Bd9839",r=f(String(b||"0"));n=await C.buyStablecoins(s,e,r,t),n={...n,value:r,account:s}}else{const r=t.getSelectedNetworkConfig(),o=r?.tokens?.stablecoin?.address;if(!o)throw new Error("Stablecoin address not found in network configuration");const i=a.amount?v(String(a.amount),a.stableCoinDecimals):"0";n={to:o,value:0n,data:E({abi:[{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}],functionName:"transfer",args:[e,i]}),account:s}}T(n),A("✅ Transaction ready! Click 'Send Transaction' to proceed.")}catch(e){B(e),A("❌ Transaction preparation failed.")}else A("❌ Wallet not connected or transaction details missing")}},"Prepare Transaction"),s&&_&&c.createElement("button",{className:x.walletButton,onClick:async()=>{B(null);try{if(!s||!_)return void A("❌ Wallet account or transaction data is missing");if(!n)return void A("❌ Network not selected");const o=t.getSelectedNetworkConfig();if(!o)return void A("❌ Network configuration not found");A("⏳ Verifying network...");const i=await k();if(!i)return void A("❌ Failed to switch to correct network. Please approve the network switch in MetaMask and try again.");if(!window.ethereum)return void A("❌ MetaMask not available");const c=await window.ethereum.request({method:"eth_chainId"}),l=parseInt(c,16);if(l!==o.chainId){const e=`Network mismatch. MetaMask is on chain ${l}, but ${n} requires chain ${o.chainId}. Please switch networks in MetaMask.`;return A(`❌ ${e}`),void B(new Error(e))}if(i.chain.id!==o.chainId){const e=`Wallet client chain mismatch. Wallet client is on chain ${i.chain.id}, but expected ${o.chainId}.`;return A(`❌ ${e}`),void B(new Error(e))}A("⏳ Sending transaction...");const d=await i.sendTransaction({..._,account:s});P(d),A("✅ Transaction sent!"),e&&e({txHash:d,network:n,token:r?.key,tokenSymbol:r?.symbol,amount:a?.amount,receivingAddress:a?.receivingAddress})}catch(e){B(e),A("❌ Transaction failed."),console.error("Transaction error:",e)}},disabled:null!==D},"Send Transaction"),S&&c.createElement("div",{className:"message-box"},S,I&&c.createElement("button",{onClick:()=>j(!M),className:x.detailsButton},M?"Hide Details":"Show Details")),M&&I&&c.createElement("div",{className:x.errorDetails},c.createElement("pre",null,I.message)),D&&c.createElement("div",{className:x.transactionLink},"✅ Transaction Hash:"," ",U()?c.createElement("a",{href:U(),target:"_blank",rel:"noopener noreferrer",className:x.explorerLink,style:{color:"#007bff",textDecoration:"underline",fontWeight:"bold",cursor:"pointer",wordBreak:"break-word"}},D.slice(0,6),"...",D.slice(-6)):c.createElement("span",{style:{wordBreak:"break-word"}},D)))},q=({onClose:e,buttonSize:t,onTransactionComplete:n})=>{const{resetSelections:r}=$();return c.createElement(P,{onClose:()=>{r(),e()},size:t},c.createElement(j,null),c.createElement(U,null),c.createElement(O,{onTransactionComplete:n}))},H=({onClose:e,buttonSize:t,networkSelector:n,onTransactionComplete:r})=>c.createElement(M,{networkSelector:n},c.createElement(W,null,c.createElement(q,{onClose:e,buttonSize:t,onTransactionComplete:r}))),V={NetworkSelector:class{constructor(e){this.merchantConfig=e,this.blacklist=e.getBlacklist(),this.availableNetworks=this.getAvailableNetworks(),this.selectedNetwork=null}getAvailableNetworks(){return Object.entries(_).reduce(((e,[t,n])=>(this.blacklist.includes(n.chainId)||(e[t]=n),e)),{})}selectNetwork(e){return null===e?(this.selectedNetwork=null,console.log("Network selection reset"),!0):this.availableNetworks[e]?(this.selectedNetwork=e,console.log(`Network selected: ${e}`),!0):(console.error(`Invalid network: ${e}`),!1)}getSelectedNetworkConfig(){return this.selectedNetwork?this.availableNetworks[this.selectedNetwork]:null}getReceivingAddress(){return this.merchantConfig.getReceivingAddress()}getTokenAmount(e){return this.merchantConfig.getTokenAmount(this.selectedNetwork,e)}},Transaction:N,Config:class{constructor(e={}){this.receivingAddress=e.receivingAddress||"",this.blacklist=e.blacklist||[],this.amounts=e.Amounts||{},this.validateConfig()}validateConfig(){if(!this.receivingAddress)throw new Error("Receiving address is required");for(const[e,t]of Object.entries(this.amounts)){if(!_[e])throw new Error(`Invalid network: ${e}`);if(!t.stablecoin||"number"!=typeof t.stablecoin||t.stablecoin<=0)throw new Error(`Invalid stablecoin amount for network ${e}`)}}getBlacklist(){return this.blacklist}getReceivingAddress(){return this.receivingAddress}getTokenAmount(e){console.log("Getting amount for network:",e),console.log("Amounts object:",this.amounts);const t=this.amounts[e]?.stablecoin;return console.log("Returning amount:",t),t||0}},Widget:({networkSelector:e,buttonSize:t="medium",onTransactionComplete:n,onSuccess:r})=>{const[a,o]=m(!1),i=n||r;return c.createElement("div",{className:x.widgetContainer},!a&&c.createElement(D,{onClick:()=>{o(!0)},size:t}),a&&c.createElement(H,{onClose:()=>{o(!1)},buttonSize:t,networkSelector:e,onTransactionComplete:i}))},PayButton:D,Dialog:P,NetworkDropdown:j};export{V as default}; +import{getWeb3 as e,getDjedContract as t,getCoinContracts as n,getDecimals as a,getOracleAddress as r,getOracleContract as i,tradeDataPriceBuySc as s,buyScIsisTx as o,buyScTx as l,approveTx as c,checkAllowance as d}from"djed-sdk";import u,{useContext as m,createContext as h,useState as p,useEffect as w,useRef as y,useCallback as k}from"react";import{defineChain as g,createWalletClient as b,custom as C,createPublicClient as f,http as v,parseEther as E,parseUnits as T,encodeFunctionData as _}from"viem";import{sepolia as N}from"viem/chains";const A={sepolia:{uri:"https://ethereum-sepolia.publicnode.com/",chainId:11155111,djedAddress:"0x624FcD0a1F9B5820c950FefD48087531d38387f4",tokens:{stablecoin:{symbol:"SOD",address:"0x6b930182787F346F18666D167e8d32166dC5eFBD",decimals:18,isDirectTransfer:!0},native:{symbol:"ETH",decimals:18,isNative:!0}},feeUI:0},"milkomeda-mainnet":{uri:"https://rpc-mainnet-cardano-evm.c1.milkomeda.com",chainId:2001,djedAddress:"0x67A30B399F5Ed499C1a6Bc0358FA6e42Ea4BCe76",tokens:{stablecoin:{symbol:"MOD",address:"0xcbA90fB1003b9D1bc6a2b66257D2585011b004e9",decimals:18,isDirectTransfer:!0},native:{symbol:"mADA",decimals:18,isNative:!0}},feeUI:0},"ethereum-classic":{uri:"https://etc.rivet.link",chainId:61,djedAddress:"0xCc3664d7021FD36B1Fe2b136e2324710c8442cCf",tokens:{stablecoin:{symbol:"ECSD",address:"0x5A7Ca94F6E969C94bef4CE5e2f90ed9d4891918A",decimals:18,isDirectTransfer:!0},native:{symbol:"ETC",decimals:18,isNative:!0}},feeUI:0}};var S=[{inputs:[{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"symbol",type:"string"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"subtractedValue",type:"uint256"}],name:"decreaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"addedValue",type:"uint256"}],name:"increaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"mint",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"burn",outputs:[],stateMutability:"nonpayable",type:"function"}];class x{constructor(e,t,n=null){this.networkUri=e,this.djedAddress=t,this.baseAssetAddress=n}async init(){if(!this.networkUri||!this.djedAddress)throw new Error("Network URI and DJED address are required");try{this.web3=await e(this.networkUri),this.djedContract=t(this.web3,this.djedAddress),this.baseAssetAddress&&(this.baseAssetContract=new this.web3.eth.Contract(S,this.baseAssetAddress));try{const{stableCoin:e,reserveCoin:t}=await n(this.djedContract,this.web3),{scDecimals:s,rcDecimals:o}=await a(e,t);this.stableCoin=e,this.reserveCoin=t,this.scDecimals=s,this.rcDecimals=o,this.oracleContract=await r(this.djedContract).then((e=>i(this.web3,e,this.djedContract._address))),this.oracleAddress=this.oracleContract._address}catch(e){if(console.error("[Transaction] Error fetching contract details:",e),e.message&&e.message.includes("execution reverted")){const e=e=>e.includes("milkomeda")?{name:"Milkomeda",chainId:"2001"}:e.includes("mordor")?{name:"Mordor Testnet",chainId:"63"}:e.includes("sepolia")?{name:"Sepolia",chainId:"11155111"}:e.includes("etc.rivet.link")?{name:"Ethereum Classic",chainId:"61"}:{name:"the selected network",chainId:"unknown"},{name:t,chainId:n}=e(this.networkUri);throw new Error(`Failed to interact with Djed contract at ${this.djedAddress} on ${t}.\n\nPossible causes:\n- The contract address may be incorrect\n- The contract may not be deployed on ${t}\n- The contract may not be a valid Djed contract\n\nPlease verify the contract address is correct for ${t} (Chain ID: ${n}).`)}throw e}}catch(e){if(console.error("[Transaction] Error initializing transaction:",e),e.message&&(e.message.includes("CONNECTION ERROR")||e.message.includes("ERR_NAME_NOT_RESOLVED"))){const e=(e=>e.includes("milkomeda")?"Milkomeda":e.includes("mordor")?"Mordor":e.includes("sepolia")?"Sepolia":"the selected network")(this.networkUri);throw new Error(`Failed to connect to ${e} RPC endpoint: ${this.networkUri}\n\nPossible causes:\n- The RPC endpoint may be temporarily unavailable\n- DNS resolution issue (check your internet connection)\n- Network firewall blocking the connection\n\nPlease try again in a few moments or check the network status.`)}throw e}}getBlockchainDetails(){return{web3Available:!!this.web3,djedContractAvailable:!!this.djedContract,stableCoinAddress:this.stableCoin?this.stableCoin._address:"N/A",reserveCoinAddress:this.reserveCoin?this.reserveCoin._address:"N/A",stableCoinDecimals:this.scDecimals,reserveCoinDecimals:this.rcDecimals,oracleAddress:this.oracleAddress||"N/A",oracleContractAvailable:!!this.oracleContract}}async handleTradeDataBuySc(e){if(!this.djedContract)throw new Error("DJED contract is not initialized");if("string"!=typeof e)throw new Error("Amount must be a string");try{return(await s(this.djedContract,this.scDecimals,e)).totalBCScaled}catch(e){throw console.error("Error fetching trade data for buying stablecoins: ",e),e}}async buyStablecoins(e,t,n){if(!this.djedContract)throw new Error("DJED contract is not initialized");try{const a="0x0232556C83791b8291E9b23BfEa7d67405Bd9839";if(this.baseAssetAddress){if(!this.baseAssetContract)throw new Error("Base Asset contract not initialized for ERC20 flow");return o(this.djedContract,e,t,n,a,this.djedAddress)}return l(this.djedContract,e,t,n,a,this.djedAddress)}catch(e){throw console.error("Error executing buyStablecoins transaction: ",e),e}}async approveBaseAsset(e,t){if(!this.baseAssetContract)throw new Error("No Base Asset contract to approve");return c(this.baseAssetContract,e,this.djedAddress,t)}async checkBaseAssetAllowance(e){return this.baseAssetContract?d(this.baseAssetContract,e,this.djedAddress):"Inf"}}var D="main_stablePayButton__UA7HC",P="main_logo__ITyEy",M="main_buttonText__N-ewy";const I=({onClick:e,size:t="medium"})=>{const n={small:{width:"200px",height:"50px",fontSize:"14px"},medium:{width:"250px",height:"60px",fontSize:"16px"},large:{width:"300px",height:"70px",fontSize:"18px"}},a={small:{width:"35px",height:"33px"},medium:{width:"40px",height:"38px"},large:{width:"45px",height:"43px"}},r=n[t]||n.medium,i=a[t]||a.medium;return u.createElement("button",{className:D,onClick:e,style:r},u.createElement("div",{className:P,style:i}),u.createElement("span",{className:M},"Pay with StablePay"))};var B={dialogOverlay:"PricingCard_dialogOverlay__0XJrE",pricingCard:"PricingCard_pricingCard__LrWb9",small:"PricingCard_small__J4CHj",medium:"PricingCard_medium__EVmTB",large:"PricingCard_large__A6pnX",dialogClose:"PricingCard_dialogClose__jJ1tM",pricingCardHeader:"PricingCard_pricingCardHeader__wGczA",allianceLogo:"PricingCard_allianceLogo__URa-U",stablepayTitle:"PricingCard_stablepayTitle__4t848",pricingCardBody:"PricingCard_pricingCardBody__0wKQn",selectField:"PricingCard_selectField__LBPoZ",transactionReview:"PricingCard_transactionReview__Ix-eL",transactionInfo:"PricingCard_transactionInfo__Ck-Rc",transactionLabel:"PricingCard_transactionLabel__GDux7",transactionValue:"PricingCard_transactionValue__q-xxp",infoSection:"PricingCard_infoSection__gyjMQ",infoIcon:"PricingCard_infoIcon__rraxD",infoText:"PricingCard_infoText__l4b7A",walletButton:"PricingCard_walletButton__llw4v",loading:"PricingCard_loading__2-tGA",error:"PricingCard_error__m5fK-",networkError:"PricingCard_networkError__zR-36",errorText:"PricingCard_errorText__qZRJt","message-box":"PricingCard_message-box__vkUKy",detailsButton:"PricingCard_detailsButton__jHglL",errorDetails:"PricingCard_errorDetails__CzN-7",loadingContainer:"PricingCard_loadingContainer__6nOVa",spinner:"PricingCard_spinner__9ucQv",spin:"PricingCard_spin__24tni"};const j=({children:e,onClose:t,size:n="medium"})=>u.createElement("div",{className:B.dialogOverlay},u.createElement("div",{className:`${B.pricingCard} ${B[n]}`},u.createElement("button",{className:B.dialogClose,onClick:t},"×"),u.createElement("div",{className:B.pricingCardHeader},u.createElement("div",{className:B.allianceLogo}),u.createElement("h2",{className:B.stablepayTitle},"StablePay")),u.createElement("div",{className:B.pricingCardBody},e)));class ${constructor(e){this.networkSelector=e,this.selectedToken=null}selectToken(e){const t=this.networkSelector.getSelectedNetworkConfig();return!(!t||!t.tokens[e])&&(this.selectedToken={key:e,...t.tokens[e]},!0)}getSelectedToken(){return this.selectedToken}getAvailableTokens(){const e=this.networkSelector.getSelectedNetworkConfig();return e?Object.entries(e.tokens).map((([e,t])=>({key:e,...t}))):[]}resetSelection(){this.selectedToken=null}}const F=h(),U=({children:e,networkSelector:t})=>{const[n]=p((()=>new $(t))),[a,r]=p(null),[i,s]=p(null),[o,l]=p(null),c=()=>{s(null),l(null)};return w((()=>{r(t.selectedNetwork)}),[t.selectedNetwork]),u.createElement(F.Provider,{value:{networkSelector:t,tokenSelector:n,selectedNetwork:a,selectedToken:i,transactionDetails:o,setTransactionDetails:l,selectNetwork:e=>!!t.selectNetwork(e)&&(r(e),c(),!0),selectToken:e=>{if(n.selectToken(e)){const e=n.getSelectedToken();return s(e),!0}return!1},resetSelections:()=>{t.selectNetwork(null),r(null),c()}}},e)},R=()=>{const e=m(F);if(void 0===e)throw new Error("useNetwork must be used within a NetworkProvider");return e},z=()=>{const{networkSelector:e,selectedNetwork:t,selectNetwork:n}=R();return u.createElement("div",{className:B.selectField},u.createElement("label",{htmlFor:"network-select"},"Select Network"),u.createElement("select",{id:"network-select",onChange:e=>{n(e.target.value)},value:t||""},u.createElement("option",{value:"",disabled:!0},"Select a network"),Object.keys(e.availableNetworks).map((e=>u.createElement("option",{key:e,value:e},e)))))},L=()=>{const{networkSelector:e,tokenSelector:t,selectedNetwork:n,selectedToken:a,selectToken:r,setTransactionDetails:i}=R(),[s,o]=p(!1),[l,c]=p(null),d=n?t.getAvailableTokens():[];return u.createElement("div",{className:B.selectField},u.createElement("label",{htmlFor:"token-select"},"Select Token"),u.createElement("select",{id:"token-select",onChange:async a=>{const s=a.target.value;c(null),o(!0);try{if(r(s)){const a=e.getSelectedNetworkConfig(),r=new x(a.uri,a.djedAddress);await r.init();const o=e.getTokenAmount(s),l=r.getBlockchainDetails();let c=null;"native"===s&&(c=await r.handleTradeDataBuySc(String(o))),i({network:n,token:s,tokenSymbol:t.getSelectedToken().symbol,amount:o,receivingAddress:e.getReceivingAddress(),djedContractAddress:a.djedAddress,isDirectTransfer:t.getSelectedToken().isDirectTransfer||!1,isNativeToken:t.getSelectedToken().isNative||!1,tradeAmount:c?c.amount:null,...l})}}catch(e){console.error("Error fetching transaction details:",e),c("Failed to fetch transaction details. Please try again.")}finally{o(!1)}},value:a?a.key:"",disabled:!n||s},u.createElement("option",{value:"",disabled:!0},n?s?"Loading...":"Select a token":"Please select a network first"),d.map((e=>u.createElement("option",{key:e.key,value:e.key},e.symbol," (",e.isDirectTransfer?"Direct Transfer":"Native",")")))),l&&u.createElement("div",{className:B.error},l))};g({id:63,name:"Mordor Testnet",network:"mordor",nativeCurrency:{decimals:18,name:"Mordor Ether",symbol:"METC"},rpcUrls:{default:{http:["https://rpc.mordor.etccooperative.org"],webSocket:["wss://rpc.mordor.etccooperative.org/ws"]}},blockExplorers:{default:{name:"BlockScout",url:"https://blockscout.com/etc/mordor"}},testnet:!0});const O=g({id:2001,name:"Milkomeda C1 Mainnet",network:"milkomeda",nativeCurrency:{decimals:18,name:"Milkomeda ADA",symbol:"mADA"},rpcUrls:{default:{http:["https://rpc-mainnet-cardano-evm.c1.milkomeda.com"]}},blockExplorers:{default:{name:"Milkomeda Explorer",url:"https://explorer-mainnet-cardano-evm.c1.milkomeda.com"}},testnet:!1}),W=g({id:61,name:"Ethereum Classic",network:"etc",nativeCurrency:{decimals:18,name:"Ethereum Classic",symbol:"ETC"},rpcUrls:{default:{http:["https://etc.rivet.link"]}},blockExplorers:{default:{name:"Blockscout",url:"https://blockscout.com/etc/mainnet"}},testnet:!1}),q=h(null),H=async e=>{if(!window.ethereum)throw new Error("MetaMask not installed");const t=(e=>{switch(e){case"sepolia":return{chainId:`0x${N.id.toString(16)}`,chainName:"Sepolia",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:N.rpcUrls.default.http,blockExplorerUrls:N.blockExplorers?.default?.url?[N.blockExplorers.default.url]:[]};case"ethereum-classic":return{chainId:`0x${W.id.toString(16)}`,chainName:"Ethereum Classic",nativeCurrency:{name:"Ethereum Classic",symbol:"ETC",decimals:18},rpcUrls:["https://etc.rivet.link"],blockExplorerUrls:["https://blockscout.com/etc/mainnet"]};case"milkomeda-mainnet":return{chainId:`0x${O.id.toString(16)}`,chainName:"Milkomeda C1 Mainnet",nativeCurrency:{name:"Milkomeda ADA",symbol:"mADA",decimals:18},rpcUrls:["https://rpc-mainnet-cardano-evm.c1.milkomeda.com"],blockExplorerUrls:["https://explorer-mainnet-cardano-evm.c1.milkomeda.com"]};default:return null}})(e);if(!t)throw new Error(`Unsupported network: ${e}`);try{await window.ethereum.request({method:"wallet_switchEthereumChain",params:[{chainId:t.chainId}]})}catch(e){if(4902!==e.code)throw 4001===e.code?new Error(`User rejected switching to ${t.chainName}. Please switch manually in MetaMask.`):new Error(`Failed to switch to ${t.chainName}: ${e.message}`);try{await window.ethereum.request({method:"wallet_addEthereumChain",params:[t]})}catch(e){if(4001===e.code)throw new Error(`User rejected adding ${t.chainName} to MetaMask. Please add it manually.`);throw new Error(`Failed to add ${t.chainName} to MetaMask: ${e.message}`)}}},V=({children:e})=>{const{selectedNetwork:t}=R(),[n,a]=p(null),[r,i]=p(null),[s,o]=p(null),[l,c]=p(null),[d,m]=p(null),[h,g]=p(null),[E,T]=p(!1),_=t?(e=>{switch(e){case"sepolia":return N;case"ethereum-classic":return W;case"milkomeda-mainnet":return O;default:return null}})(t):null,A=_?_.id:null,S=y(null),x=y(null),D=k((()=>{a(null),i(null),o(null),c(null),m(null),g(null)}),[]),P=k((async e=>{const n=parseInt(e,16);if(c(n),_&&n===A){if(g(null),window.ethereum&&_){const e=b({chain:_,transport:C(window.ethereum)});a(e)}}else if(_&&n!==A){g(`Wrong network detected. Please switch to ${_?.name||t||"selected network"}`)}}),[_,A,t]);x.current=P;const M=k((async e=>{if(0===e.length){if(D(),window.ethereum){const e=S.current,t=x.current;e&&window.ethereum.removeListener("accountsChanged",e),t&&window.ethereum.removeListener("chainChanged",t)}}else if(o(e[0]),_)try{const t=f({chain:_,transport:v()});i(t);const n=await t.getBalance({address:e[0]});m(parseFloat(n)/Math.pow(10,18))}catch(e){console.error("Error fetching balance:",e),m(null)}}),[_,D]);S.current=M;const I=k((()=>{if(D(),window.ethereum){const e=S.current,t=x.current;e&&window.ethereum.removeListener("accountsChanged",e),t&&window.ethereum.removeListener("chainChanged",t)}}),[D]),B=k((()=>{_&&i(f({chain:_,transport:v()}))}),[_]),j=k((async()=>{if(!window.ethereum)return g("Please install MetaMask or another Web3 wallet"),!1;if(!t||!_)return g("Please select a network first"),!1;T(!0),g(null);try{const e=await window.ethereum.request({method:"eth_requestAccounts"});if(0===e.length)throw new Error("No wallet address found. Please unlock your wallet.");const n=await window.ethereum.request({method:"eth_chainId"});parseInt(n,16)!==A&&await H(t);const r=b({chain:_,transport:C(window.ethereum)});a(r),o(e[0]),c(A);const s=f({chain:_,transport:v()});i(s);try{const t=await s.getBalance({address:e[0]});m(parseFloat(t)/Math.pow(10,18))}catch(e){console.error("Error fetching balance:",e),m(null)}return S.current=M,x.current=P,window.ethereum.on("accountsChanged",M),window.ethereum.on("chainChanged",P),!0}catch(e){return console.error("Error connecting wallet:",e),g(e.message),!1}finally{T(!1)}}),[t,_,A,M,P]),$=k((async()=>{if(!(window.ethereum&&t&&_&&s)){return g("Wallet not connected or network not selected"),null}try{const e=await window.ethereum.request({method:"eth_chainId"});if(parseInt(e,16)!==A){g(null),await H(t);const e=500;await new Promise((t=>setTimeout(t,e)));const n=await window.ethereum.request({method:"eth_chainId"}),a=parseInt(n,16);if(a!==A)throw new Error(`Failed to switch network. MetaMask is still on chain ${a}, expected ${A}`)}const n=b({chain:_,transport:C(window.ethereum)});return a(n),c(A),g(null),n}catch(e){return g(e.message),null}}),[t,_,A,s]),F=y(t);return w((()=>{if(null!==F.current&&F.current!==t&&s&&(D(),window.ethereum)){const e=S.current,t=x.current;e&&window.ethereum.removeListener("accountsChanged",e),t&&window.ethereum.removeListener("chainChanged",t)}F.current=t}),[t,s,D]),w((()=>{B()}),[B]),u.createElement(q.Provider,{value:{walletClient:n,publicClient:r,account:s,chainId:l,balance:d,error:h,isConnecting:E,connectWallet:j,disconnectWallet:I,ensureCorrectNetwork:$,expectedChainId:A}},e)},J=({onTransactionComplete:e})=>{const{networkSelector:t,selectedNetwork:n,selectedToken:a,transactionDetails:r,setTransactionDetails:i}=R(),{connectWallet:s,account:o,walletClient:l,publicClient:c,isConnecting:d,ensureCorrectNetwork:h,expectedChainId:y}=(()=>{const e=m(q);if(!e)throw new Error("useWallet must be used within a WalletProvider");return e})(),[k,g]=p(null),[b,C]=p(null),[f,v]=p(null),[N,A]=p(""),[S,D]=p(null),[P,M]=p(null),[I,j]=p(!1);if(w((()=>{v(null),C(null),A(""),M(null),D(null)}),[n,a]),w((()=>{(async()=>{if(n&&a)try{const e=t.getSelectedNetworkConfig(),r=t.getReceivingAddress(),s=t.getTokenAmount(a.key),o=new x(e.uri,e.djedAddress);await o.init(),g(o);let l=null;if("native"===a.key)try{l=await o.handleTradeDataBuySc(String(s)),C(l)}catch(e){console.error("Error fetching trade data:",e)}i({network:n,token:a.key,tokenSymbol:a.symbol,amount:s||"0",receivingAddress:r,djedContractAddress:e.djedAddress,isDirectTransfer:a.isDirectTransfer||!1,isNativeToken:a.isNative||!1,tradeAmount:l?l.amount:null,...o.getBlockchainDetails()})}catch(e){console.error("Error initializing transaction:",e)}})()}),[n,a,t,i]),!r)return u.createElement("div",{className:B.loading},"Initializing transaction...");const $=()=>{if(!S||!n)return null;const e={"ethereum-classic":"https://blockscout.com/etc/mainnet/tx/",sepolia:"https://sepolia.etherscan.io/tx/","milkomeda-mainnet":"https://explorer-mainnet-cardano-evm.c1.milkomeda.com/tx/"};return e[n]?`${e[n]}${S}`:null};return u.createElement("div",{className:B.transactionReview},u.createElement("div",{className:B.transactionInfo},u.createElement("span",{className:B.transactionLabel},"Network:"),u.createElement("span",{className:B.transactionValue},r.network)),u.createElement("div",{className:B.transactionInfo},u.createElement("span",{className:B.transactionLabel},"You Pay:"),u.createElement("span",{className:B.transactionValue},"stablecoin"===a.key?`${r.amount} ${r.tokenSymbol}`:`${b||"Calculating..."} ${r.tokenSymbol}`)),u.createElement("button",{className:B.walletButton,onClick:async()=>{await s()},disabled:d},d?"Connecting...":"Connect Wallet"),o&&!f&&u.createElement("button",{className:B.walletButton,onClick:async()=>{if(o&&r&&k)try{v(null),M(null),A("⏳ Preparing transaction...");const e=r.receivingAddress;let n;if("native"===a.key){const t="0x0232556C83791b8291E9b23BfEa7d67405Bd9839",a=E(String(b||"0"));n=await k.buyStablecoins(o,e,a,t),n={...n,value:a,account:o}}else{const a=t.getSelectedNetworkConfig(),i=a?.tokens?.stablecoin?.address;if(!i)throw new Error("Stablecoin address not found in network configuration");const s=r.amount?T(String(r.amount),r.stableCoinDecimals):"0";n={to:i,value:0n,data:_({abi:[{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}],functionName:"transfer",args:[e,s]}),account:o}}v(n),A("✅ Transaction ready! Click 'Send Transaction' to proceed.")}catch(e){M(e),A("❌ Transaction preparation failed.")}else A("❌ Wallet not connected or transaction details missing")}},"Prepare Transaction"),o&&f&&u.createElement("button",{className:B.walletButton,onClick:async()=>{M(null);try{if(!o||!f)return void A("❌ Wallet account or transaction data is missing");if(!n)return void A("❌ Network not selected");const i=t.getSelectedNetworkConfig();if(!i)return void A("❌ Network configuration not found");A("⏳ Verifying network...");const s=await h();if(!s)return void A("❌ Failed to switch to correct network. Please approve the network switch in MetaMask and try again.");if(!window.ethereum)return void A("❌ MetaMask not available");const l=await window.ethereum.request({method:"eth_chainId"}),c=parseInt(l,16);if(c!==i.chainId){const e=`Network mismatch. MetaMask is on chain ${c}, but ${n} requires chain ${i.chainId}. Please switch networks in MetaMask.`;return A(`❌ ${e}`),void M(new Error(e))}if(s.chain.id!==i.chainId){const e=`Wallet client chain mismatch. Wallet client is on chain ${s.chain.id}, but expected ${i.chainId}.`;return A(`❌ ${e}`),void M(new Error(e))}A("⏳ Sending transaction...");const d=await s.sendTransaction({...f,account:o});D(d),A("✅ Transaction sent!"),e&&e({txHash:d,network:n,token:a?.key,tokenSymbol:a?.symbol,amount:r?.amount,receivingAddress:r?.receivingAddress})}catch(e){M(e),A("❌ Transaction failed."),console.error("Transaction error:",e)}},disabled:null!==S},"Send Transaction"),N&&u.createElement("div",{className:"message-box"},N,P&&u.createElement("button",{onClick:()=>j(!I),className:B.detailsButton},I?"Hide Details":"Show Details")),I&&P&&u.createElement("div",{className:B.errorDetails},u.createElement("pre",null,P.message)),S&&u.createElement("div",{className:B.transactionLink},"✅ Transaction Hash:"," ",$()?u.createElement("a",{href:$(),target:"_blank",rel:"noopener noreferrer",className:B.explorerLink,style:{color:"#007bff",textDecoration:"underline",fontWeight:"bold",cursor:"pointer",wordBreak:"break-word"}},S.slice(0,6),"...",S.slice(-6)):u.createElement("span",{style:{wordBreak:"break-word"}},S)))},G=({onClose:e,buttonSize:t,onTransactionComplete:n})=>{const{resetSelections:a}=R();return u.createElement(j,{onClose:()=>{a(),e()},size:t},u.createElement(z,null),u.createElement(L,null),u.createElement(J,{onTransactionComplete:n}))},K=({onClose:e,buttonSize:t,networkSelector:n,onTransactionComplete:a})=>u.createElement(U,{networkSelector:n},u.createElement(V,null,u.createElement(G,{onClose:e,buttonSize:t,onTransactionComplete:a}))),Q={NetworkSelector:class{constructor(e){this.merchantConfig=e,this.blacklist=e.getBlacklist(),this.availableNetworks=this.getAvailableNetworks(),this.selectedNetwork=null}getAvailableNetworks(){return Object.entries(A).reduce(((e,[t,n])=>(this.blacklist.includes(n.chainId)||(e[t]=n),e)),{})}selectNetwork(e){return null===e?(this.selectedNetwork=null,console.log("Network selection reset"),!0):this.availableNetworks[e]?(this.selectedNetwork=e,console.log(`Network selected: ${e}`),!0):(console.error(`Invalid network: ${e}`),!1)}getSelectedNetworkConfig(){return this.selectedNetwork?this.availableNetworks[this.selectedNetwork]:null}getReceivingAddress(){return this.merchantConfig.getReceivingAddress()}getTokenAmount(e){return this.merchantConfig.getTokenAmount(this.selectedNetwork,e)}},Transaction:x,Config:class{constructor(e={}){this.receivingAddress=e.receivingAddress||"",this.blacklist=e.blacklist||[],this.amounts=e.Amounts||{},this.validateConfig()}validateConfig(){if(!this.receivingAddress)throw new Error("Receiving address is required");for(const[e,t]of Object.entries(this.amounts)){if(!A[e])throw new Error(`Invalid network: ${e}`);if(!t.stablecoin||"number"!=typeof t.stablecoin||t.stablecoin<=0)throw new Error(`Invalid stablecoin amount for network ${e}`)}}getBlacklist(){return this.blacklist}getReceivingAddress(){return this.receivingAddress}getTokenAmount(e){console.log("Getting amount for network:",e),console.log("Amounts object:",this.amounts);const t=this.amounts[e]?.stablecoin;return console.log("Returning amount:",t),t||0}},Widget:({networkSelector:e,buttonSize:t="medium",onTransactionComplete:n,onSuccess:a})=>{const[r,i]=p(!1),s=n||a;return u.createElement("div",{className:B.widgetContainer},!r&&u.createElement(I,{onClick:()=>{i(!0)},size:t}),r&&u.createElement(K,{onClose:()=>{i(!1)},buttonSize:t,networkSelector:e,onTransactionComplete:s}))},PayButton:I,Dialog:j,NetworkDropdown:z};export{Q as default}; diff --git a/stablepay-sdk/dist/umd/index.js b/stablepay-sdk/dist/umd/index.js index 0e43e66..c83cdb3 100644 --- a/stablepay-sdk/dist/umd/index.js +++ b/stablepay-sdk/dist/umd/index.js @@ -1,2 +1,2 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("djed-sdk"),require("react"),require("viem"),require("viem/chains")):"function"==typeof define&&define.amd?define(["djed-sdk","react","viem","viem/chains"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).StablePay=t(e.DjedSdk,e.React,e.viem,e.viemChains)}(this,(function(e,t,n,r){"use strict";const a={sepolia:{uri:"https://ethereum-sepolia.publicnode.com/",chainId:11155111,djedAddress:"0x624FcD0a1F9B5820c950FefD48087531d38387f4",tokens:{stablecoin:{symbol:"SOD",address:"0x6b930182787F346F18666D167e8d32166dC5eFBD",decimals:18,isDirectTransfer:!0},native:{symbol:"ETH",decimals:18,isNative:!0}},feeUI:0},"milkomeda-mainnet":{uri:"https://rpc-mainnet-cardano-evm.c1.milkomeda.com",chainId:2001,djedAddress:"0x67A30B399F5Ed499C1a6Bc0358FA6e42Ea4BCe76",tokens:{stablecoin:{symbol:"MOD",address:"0xcbA90fB1003b9D1bc6a2b66257D2585011b004e9",decimals:18,isDirectTransfer:!0},native:{symbol:"mADA",decimals:18,isNative:!0}},feeUI:0},"ethereum-classic":{uri:"https://etc.rivet.link",chainId:61,djedAddress:"0xCc3664d7021FD36B1Fe2b136e2324710c8442cCf",tokens:{stablecoin:{symbol:"ECSD",address:"0x5A7Ca94F6E969C94bef4CE5e2f90ed9d4891918A",decimals:18,isDirectTransfer:!0},native:{symbol:"ETC",decimals:18,isNative:!0}},feeUI:0}};class i{constructor(e,t){this.networkUri=e,this.djedAddress=t}async init(){if(!this.networkUri||!this.djedAddress)throw new Error("Network URI and DJED address are required");try{this.web3=await e.getWeb3(this.networkUri),this.djedContract=e.getDjedContract(this.web3,this.djedAddress);try{const{stableCoin:t,reserveCoin:n}=await e.getCoinContracts(this.djedContract,this.web3),{scDecimals:r,rcDecimals:a}=await e.getDecimals(t,n);this.stableCoin=t,this.reserveCoin=n,this.scDecimals=r,this.rcDecimals=a,this.oracleContract=await e.getOracleAddress(this.djedContract).then((t=>e.getOracleContract(this.web3,t,this.djedContract._address))),this.oracleAddress=this.oracleContract._address}catch(e){if(console.error("[Transaction] Error fetching contract details:",e),e.message&&e.message.includes("execution reverted")){const e=e=>e.includes("milkomeda")?{name:"Milkomeda",chainId:"2001"}:e.includes("mordor")?{name:"Mordor Testnet",chainId:"63"}:e.includes("sepolia")?{name:"Sepolia",chainId:"11155111"}:e.includes("etc.rivet.link")?{name:"Ethereum Classic",chainId:"61"}:{name:"the selected network",chainId:"unknown"},{name:t,chainId:n}=e(this.networkUri);throw new Error(`Failed to interact with Djed contract at ${this.djedAddress} on ${t}.\n\nPossible causes:\n- The contract address may be incorrect\n- The contract may not be deployed on ${t}\n- The contract may not be a valid Djed contract\n\nPlease verify the contract address is correct for ${t} (Chain ID: ${n}).`)}throw e}}catch(e){if(console.error("[Transaction] Error initializing transaction:",e),e.message&&(e.message.includes("CONNECTION ERROR")||e.message.includes("ERR_NAME_NOT_RESOLVED"))){const e=(e=>e.includes("milkomeda")?"Milkomeda":e.includes("mordor")?"Mordor":e.includes("sepolia")?"Sepolia":"the selected network")(this.networkUri);throw new Error(`Failed to connect to ${e} RPC endpoint: ${this.networkUri}\n\nPossible causes:\n- The RPC endpoint may be temporarily unavailable\n- DNS resolution issue (check your internet connection)\n- Network firewall blocking the connection\n\nPlease try again in a few moments or check the network status.`)}throw e}}getBlockchainDetails(){return{web3Available:!!this.web3,djedContractAvailable:!!this.djedContract,stableCoinAddress:this.stableCoin?this.stableCoin._address:"N/A",reserveCoinAddress:this.reserveCoin?this.reserveCoin._address:"N/A",stableCoinDecimals:this.scDecimals,reserveCoinDecimals:this.rcDecimals,oracleAddress:this.oracleAddress||"N/A",oracleContractAvailable:!!this.oracleContract}}async handleTradeDataBuySc(t){if(!this.djedContract)throw new Error("DJED contract is not initialized");if("string"!=typeof t)throw new Error("Amount must be a string");try{return(await e.tradeDataPriceBuySc(this.djedContract,this.scDecimals,t)).totalBCScaled}catch(e){throw console.error("Error fetching trade data for buying stablecoins: ",e),e}}async buyStablecoins(t,n,r){if(!this.djedContract)throw new Error("DJED contract is not initialized");try{const a="0x0232556C83791b8291E9b23BfEa7d67405Bd9839";return await e.buyScTx(this.djedContract,t,n,r,a,this.djedAddress)}catch(e){throw console.error("Error executing buyStablecoins transaction: ",e),e}}}var o="main_stablePayButton__UA7HC",s="main_logo__ITyEy",c="main_buttonText__N-ewy";const l=({onClick:e,size:n="medium"})=>{const r={small:{width:"200px",height:"50px",fontSize:"14px"},medium:{width:"250px",height:"60px",fontSize:"16px"},large:{width:"300px",height:"70px",fontSize:"18px"}},a={small:{width:"35px",height:"33px"},medium:{width:"40px",height:"38px"},large:{width:"45px",height:"43px"}},i=r[n]||r.medium,l=a[n]||a.medium;return t.createElement("button",{className:o,onClick:e,style:i},t.createElement("div",{className:s,style:l}),t.createElement("span",{className:c},"Pay with StablePay"))};var d={dialogOverlay:"PricingCard_dialogOverlay__0XJrE",pricingCard:"PricingCard_pricingCard__LrWb9",small:"PricingCard_small__J4CHj",medium:"PricingCard_medium__EVmTB",large:"PricingCard_large__A6pnX",dialogClose:"PricingCard_dialogClose__jJ1tM",pricingCardHeader:"PricingCard_pricingCardHeader__wGczA",allianceLogo:"PricingCard_allianceLogo__URa-U",stablepayTitle:"PricingCard_stablepayTitle__4t848",pricingCardBody:"PricingCard_pricingCardBody__0wKQn",selectField:"PricingCard_selectField__LBPoZ",transactionReview:"PricingCard_transactionReview__Ix-eL",transactionInfo:"PricingCard_transactionInfo__Ck-Rc",transactionLabel:"PricingCard_transactionLabel__GDux7",transactionValue:"PricingCard_transactionValue__q-xxp",infoSection:"PricingCard_infoSection__gyjMQ",infoIcon:"PricingCard_infoIcon__rraxD",infoText:"PricingCard_infoText__l4b7A",walletButton:"PricingCard_walletButton__llw4v",loading:"PricingCard_loading__2-tGA",error:"PricingCard_error__m5fK-",networkError:"PricingCard_networkError__zR-36",errorText:"PricingCard_errorText__qZRJt","message-box":"PricingCard_message-box__vkUKy",detailsButton:"PricingCard_detailsButton__jHglL",errorDetails:"PricingCard_errorDetails__CzN-7",loadingContainer:"PricingCard_loadingContainer__6nOVa",spinner:"PricingCard_spinner__9ucQv",spin:"PricingCard_spin__24tni"};const u=({children:e,onClose:n,size:r="medium"})=>t.createElement("div",{className:d.dialogOverlay},t.createElement("div",{className:`${d.pricingCard} ${d[r]}`},t.createElement("button",{className:d.dialogClose,onClick:n},"×"),t.createElement("div",{className:d.pricingCardHeader},t.createElement("div",{className:d.allianceLogo}),t.createElement("h2",{className:d.stablepayTitle},"StablePay")),t.createElement("div",{className:d.pricingCardBody},e)));class m{constructor(e){this.networkSelector=e,this.selectedToken=null}selectToken(e){const t=this.networkSelector.getSelectedNetworkConfig();return!(!t||!t.tokens[e])&&(this.selectedToken={key:e,...t.tokens[e]},!0)}getSelectedToken(){return this.selectedToken}getAvailableTokens(){const e=this.networkSelector.getSelectedNetworkConfig();return e?Object.entries(e.tokens).map((([e,t])=>({key:e,...t}))):[]}resetSelection(){this.selectedToken=null}}const h=t.createContext(),w=({children:e,networkSelector:n})=>{const[r]=t.useState((()=>new m(n))),[a,i]=t.useState(null),[o,s]=t.useState(null),[c,l]=t.useState(null),d=()=>{s(null),l(null)};return t.useEffect((()=>{i(n.selectedNetwork)}),[n.selectedNetwork]),t.createElement(h.Provider,{value:{networkSelector:n,tokenSelector:r,selectedNetwork:a,selectedToken:o,transactionDetails:c,setTransactionDetails:l,selectNetwork:e=>!!n.selectNetwork(e)&&(i(e),d(),!0),selectToken:e=>{if(r.selectToken(e)){const e=r.getSelectedToken();return s(e),!0}return!1},resetSelections:()=>{n.selectNetwork(null),i(null),d()}}},e)},k=()=>{const e=t.useContext(h);if(void 0===e)throw new Error("useNetwork must be used within a NetworkProvider");return e},g=()=>{const{networkSelector:e,selectedNetwork:n,selectNetwork:r}=k();return t.createElement("div",{className:d.selectField},t.createElement("label",{htmlFor:"network-select"},"Select Network"),t.createElement("select",{id:"network-select",onChange:e=>{r(e.target.value)},value:n||""},t.createElement("option",{value:"",disabled:!0},"Select a network"),Object.keys(e.availableNetworks).map((e=>t.createElement("option",{key:e,value:e},e)))))},C=()=>{const{networkSelector:e,tokenSelector:n,selectedNetwork:r,selectedToken:a,selectToken:o,setTransactionDetails:s}=k(),[c,l]=t.useState(!1),[u,m]=t.useState(null),h=r?n.getAvailableTokens():[];return t.createElement("div",{className:d.selectField},t.createElement("label",{htmlFor:"token-select"},"Select Token"),t.createElement("select",{id:"token-select",onChange:async t=>{const a=t.target.value;m(null),l(!0);try{if(o(a)){const t=e.getSelectedNetworkConfig(),o=new i(t.uri,t.djedAddress);await o.init();const c=e.getTokenAmount(a),l=o.getBlockchainDetails();let d=null;"native"===a&&(d=await o.handleTradeDataBuySc(String(c))),s({network:r,token:a,tokenSymbol:n.getSelectedToken().symbol,amount:c,receivingAddress:e.getReceivingAddress(),djedContractAddress:t.djedAddress,isDirectTransfer:n.getSelectedToken().isDirectTransfer||!1,isNativeToken:n.getSelectedToken().isNative||!1,tradeAmount:d?d.amount:null,...l})}}catch(e){console.error("Error fetching transaction details:",e),m("Failed to fetch transaction details. Please try again.")}finally{l(!1)}},value:a?a.key:"",disabled:!r||c},t.createElement("option",{value:"",disabled:!0},r?c?"Loading...":"Select a token":"Please select a network first"),h.map((e=>t.createElement("option",{key:e.key,value:e.key},e.symbol," (",e.isDirectTransfer?"Direct Transfer":"Native",")")))),u&&t.createElement("div",{className:d.error},u))};n.defineChain({id:63,name:"Mordor Testnet",network:"mordor",nativeCurrency:{decimals:18,name:"Mordor Ether",symbol:"METC"},rpcUrls:{default:{http:["https://rpc.mordor.etccooperative.org"],webSocket:["wss://rpc.mordor.etccooperative.org/ws"]}},blockExplorers:{default:{name:"BlockScout",url:"https://blockscout.com/etc/mordor"}},testnet:!0});const b=n.defineChain({id:2001,name:"Milkomeda C1 Mainnet",network:"milkomeda",nativeCurrency:{decimals:18,name:"Milkomeda ADA",symbol:"mADA"},rpcUrls:{default:{http:["https://rpc-mainnet-cardano-evm.c1.milkomeda.com"]}},blockExplorers:{default:{name:"Milkomeda Explorer",url:"https://explorer-mainnet-cardano-evm.c1.milkomeda.com"}},testnet:!1}),p=n.defineChain({id:61,name:"Ethereum Classic",network:"etc",nativeCurrency:{decimals:18,name:"Ethereum Classic",symbol:"ETC"},rpcUrls:{default:{http:["https://etc.rivet.link"]}},blockExplorers:{default:{name:"Blockscout",url:"https://blockscout.com/etc/mainnet"}},testnet:!1}),f=t.createContext(null),v=async e=>{if(!window.ethereum)throw new Error("MetaMask not installed");const t=(e=>{switch(e){case"sepolia":return{chainId:`0x${r.sepolia.id.toString(16)}`,chainName:"Sepolia",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:r.sepolia.rpcUrls.default.http,blockExplorerUrls:r.sepolia.blockExplorers?.default?.url?[r.sepolia.blockExplorers.default.url]:[]};case"ethereum-classic":return{chainId:`0x${p.id.toString(16)}`,chainName:"Ethereum Classic",nativeCurrency:{name:"Ethereum Classic",symbol:"ETC",decimals:18},rpcUrls:["https://etc.rivet.link"],blockExplorerUrls:["https://blockscout.com/etc/mainnet"]};case"milkomeda-mainnet":return{chainId:`0x${b.id.toString(16)}`,chainName:"Milkomeda C1 Mainnet",nativeCurrency:{name:"Milkomeda ADA",symbol:"mADA",decimals:18},rpcUrls:["https://rpc-mainnet-cardano-evm.c1.milkomeda.com"],blockExplorerUrls:["https://explorer-mainnet-cardano-evm.c1.milkomeda.com"]};default:return null}})(e);if(!t)throw new Error(`Unsupported network: ${e}`);try{await window.ethereum.request({method:"wallet_switchEthereumChain",params:[{chainId:t.chainId}]})}catch(e){if(4902!==e.code)throw 4001===e.code?new Error(`User rejected switching to ${t.chainName}. Please switch manually in MetaMask.`):new Error(`Failed to switch to ${t.chainName}: ${e.message}`);try{await window.ethereum.request({method:"wallet_addEthereumChain",params:[t]})}catch(e){if(4001===e.code)throw new Error(`User rejected adding ${t.chainName} to MetaMask. Please add it manually.`);throw new Error(`Failed to add ${t.chainName} to MetaMask: ${e.message}`)}}},y=({children:e})=>{const{selectedNetwork:a}=k(),[i,o]=t.useState(null),[s,c]=t.useState(null),[l,d]=t.useState(null),[u,m]=t.useState(null),[h,w]=t.useState(null),[g,C]=t.useState(null),[y,E]=t.useState(!1),_=a?(e=>{switch(e){case"sepolia":return r.sepolia;case"ethereum-classic":return p;case"milkomeda-mainnet":return b;default:return null}})(a):null,S=_?_.id:null,N=t.useRef(null),T=t.useRef(null),A=t.useCallback((()=>{o(null),c(null),d(null),m(null),w(null),C(null)}),[]),D=t.useCallback((async e=>{const t=parseInt(e,16);if(m(t),_&&t===S){if(C(null),window.ethereum&&_){const e=n.createWalletClient({chain:_,transport:n.custom(window.ethereum)});o(e)}}else if(_&&t!==S){C(`Wrong network detected. Please switch to ${_?.name||a||"selected network"}`)}}),[_,S,a]);T.current=D;const x=t.useCallback((async e=>{if(0===e.length){if(A(),window.ethereum){const e=N.current,t=T.current;e&&window.ethereum.removeListener("accountsChanged",e),t&&window.ethereum.removeListener("chainChanged",t)}}else if(d(e[0]),_)try{const t=n.createPublicClient({chain:_,transport:n.http()});c(t);const r=await t.getBalance({address:e[0]});w(parseFloat(r)/Math.pow(10,18))}catch(e){console.error("Error fetching balance:",e),w(null)}}),[_,A]);N.current=x;const P=t.useCallback((()=>{if(A(),window.ethereum){const e=N.current,t=T.current;e&&window.ethereum.removeListener("accountsChanged",e),t&&window.ethereum.removeListener("chainChanged",t)}}),[A]),I=t.useCallback((()=>{_&&c(n.createPublicClient({chain:_,transport:n.http()}))}),[_]),j=t.useCallback((async()=>{if(!window.ethereum)return C("Please install MetaMask or another Web3 wallet"),!1;if(!a||!_)return C("Please select a network first"),!1;E(!0),C(null);try{const e=await window.ethereum.request({method:"eth_requestAccounts"});if(0===e.length)throw new Error("No wallet address found. Please unlock your wallet.");const t=await window.ethereum.request({method:"eth_chainId"});parseInt(t,16)!==S&&await v(a);const r=n.createWalletClient({chain:_,transport:n.custom(window.ethereum)});o(r),d(e[0]),m(S);const i=n.createPublicClient({chain:_,transport:n.http()});c(i);try{const t=await i.getBalance({address:e[0]});w(parseFloat(t)/Math.pow(10,18))}catch(e){console.error("Error fetching balance:",e),w(null)}return N.current=x,T.current=D,window.ethereum.on("accountsChanged",x),window.ethereum.on("chainChanged",D),!0}catch(e){return console.error("Error connecting wallet:",e),C(e.message),!1}finally{E(!1)}}),[a,_,S,x,D]),B=t.useCallback((async()=>{if(!(window.ethereum&&a&&_&&l)){return C("Wallet not connected or network not selected"),null}try{const e=await window.ethereum.request({method:"eth_chainId"});if(parseInt(e,16)!==S){C(null),await v(a);const e=500;await new Promise((t=>setTimeout(t,e)));const t=await window.ethereum.request({method:"eth_chainId"}),n=parseInt(t,16);if(n!==S)throw new Error(`Failed to switch network. MetaMask is still on chain ${n}, expected ${S}`)}const t=n.createWalletClient({chain:_,transport:n.custom(window.ethereum)});return o(t),m(S),C(null),t}catch(e){return C(e.message),null}}),[a,_,S,l]),M=t.useRef(a);return t.useEffect((()=>{if(null!==M.current&&M.current!==a&&l&&(A(),window.ethereum)){const e=N.current,t=T.current;e&&window.ethereum.removeListener("accountsChanged",e),t&&window.ethereum.removeListener("chainChanged",t)}M.current=a}),[a,l,A]),t.useEffect((()=>{I()}),[I]),t.createElement(f.Provider,{value:{walletClient:i,publicClient:s,account:l,chainId:u,balance:h,error:g,isConnecting:y,connectWallet:j,disconnectWallet:P,ensureCorrectNetwork:B,expectedChainId:S}},e)},E=({onTransactionComplete:e})=>{const{networkSelector:r,selectedNetwork:a,selectedToken:o,transactionDetails:s,setTransactionDetails:c}=k(),{connectWallet:l,account:u,walletClient:m,publicClient:h,isConnecting:w,ensureCorrectNetwork:g,expectedChainId:C}=(()=>{const e=t.useContext(f);if(!e)throw new Error("useWallet must be used within a WalletProvider");return e})(),[b,p]=t.useState(null),[v,y]=t.useState(null),[E,_]=t.useState(null),[S,N]=t.useState(""),[T,A]=t.useState(null),[D,x]=t.useState(null),[P,I]=t.useState(!1);if(t.useEffect((()=>{_(null),y(null),N(""),x(null),A(null)}),[a,o]),t.useEffect((()=>{(async()=>{if(a&&o)try{const e=r.getSelectedNetworkConfig(),t=r.getReceivingAddress(),n=r.getTokenAmount(o.key),s=new i(e.uri,e.djedAddress);await s.init(),p(s);let l=null;if("native"===o.key)try{l=await s.handleTradeDataBuySc(String(n)),y(l)}catch(e){console.error("Error fetching trade data:",e)}c({network:a,token:o.key,tokenSymbol:o.symbol,amount:n||"0",receivingAddress:t,djedContractAddress:e.djedAddress,isDirectTransfer:o.isDirectTransfer||!1,isNativeToken:o.isNative||!1,tradeAmount:l?l.amount:null,...s.getBlockchainDetails()})}catch(e){console.error("Error initializing transaction:",e)}})()}),[a,o,r,c]),!s)return t.createElement("div",{className:d.loading},"Initializing transaction...");const j=()=>{if(!T||!a)return null;const e={"ethereum-classic":"https://blockscout.com/etc/mainnet/tx/",sepolia:"https://sepolia.etherscan.io/tx/","milkomeda-mainnet":"https://explorer-mainnet-cardano-evm.c1.milkomeda.com/tx/"};return e[a]?`${e[a]}${T}`:null};return t.createElement("div",{className:d.transactionReview},t.createElement("div",{className:d.transactionInfo},t.createElement("span",{className:d.transactionLabel},"Network:"),t.createElement("span",{className:d.transactionValue},s.network)),t.createElement("div",{className:d.transactionInfo},t.createElement("span",{className:d.transactionLabel},"You Pay:"),t.createElement("span",{className:d.transactionValue},"stablecoin"===o.key?`${s.amount} ${s.tokenSymbol}`:`${v||"Calculating..."} ${s.tokenSymbol}`)),t.createElement("button",{className:d.walletButton,onClick:async()=>{await l()},disabled:w},w?"Connecting...":"Connect Wallet"),u&&!E&&t.createElement("button",{className:d.walletButton,onClick:async()=>{if(u&&s&&b)try{_(null),x(null),N("⏳ Preparing transaction...");const e=s.receivingAddress;let t;if("native"===o.key){const r="0x0232556C83791b8291E9b23BfEa7d67405Bd9839",a=v||"0",i=n.parseEther(String(a));t=await b.buyStablecoins(u,e,i,r),t={...t,value:i,account:u}}else{const a=r.getSelectedNetworkConfig(),i=a?.tokens?.stablecoin?.address;if(!i)throw new Error("Stablecoin address not found in network configuration");const o=s.amount?n.parseUnits(String(s.amount),s.stableCoinDecimals):"0";t={to:i,value:0n,data:n.encodeFunctionData({abi:[{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}],functionName:"transfer",args:[e,o]}),account:u}}_(t),N("✅ Transaction ready! Click 'Send Transaction' to proceed.")}catch(e){x(e),N("❌ Transaction preparation failed.")}else N("❌ Wallet not connected or transaction details missing")}},"Prepare Transaction"),u&&E&&t.createElement("button",{className:d.walletButton,onClick:async()=>{x(null);try{if(!u||!E)return void N("❌ Wallet account or transaction data is missing");if(!a)return void N("❌ Network not selected");const t=r.getSelectedNetworkConfig();if(!t)return void N("❌ Network configuration not found");N("⏳ Verifying network...");const n=await g();if(!n)return void N("❌ Failed to switch to correct network. Please approve the network switch in MetaMask and try again.");if(!window.ethereum)return void N("❌ MetaMask not available");const i=await window.ethereum.request({method:"eth_chainId"}),c=parseInt(i,16);if(c!==t.chainId){const e=`Network mismatch. MetaMask is on chain ${c}, but ${a} requires chain ${t.chainId}. Please switch networks in MetaMask.`;return N(`❌ ${e}`),void x(new Error(e))}if(n.chain.id!==t.chainId){const e=`Wallet client chain mismatch. Wallet client is on chain ${n.chain.id}, but expected ${t.chainId}.`;return N(`❌ ${e}`),void x(new Error(e))}N("⏳ Sending transaction...");const l=await n.sendTransaction({...E,account:u});A(l),N("✅ Transaction sent!"),e&&e({txHash:l,network:a,token:o?.key,tokenSymbol:o?.symbol,amount:s?.amount,receivingAddress:s?.receivingAddress})}catch(e){x(e),N("❌ Transaction failed."),console.error("Transaction error:",e)}},disabled:null!==T},"Send Transaction"),S&&t.createElement("div",{className:"message-box"},S,D&&t.createElement("button",{onClick:()=>I(!P),className:d.detailsButton},P?"Hide Details":"Show Details")),P&&D&&t.createElement("div",{className:d.errorDetails},t.createElement("pre",null,D.message)),T&&t.createElement("div",{className:d.transactionLink},"✅ Transaction Hash:"," ",j()?t.createElement("a",{href:j(),target:"_blank",rel:"noopener noreferrer",className:d.explorerLink,style:{color:"#007bff",textDecoration:"underline",fontWeight:"bold",cursor:"pointer",wordBreak:"break-word"}},T.slice(0,6),"...",T.slice(-6)):t.createElement("span",{style:{wordBreak:"break-word"}},T)))},_=({onClose:e,buttonSize:n,onTransactionComplete:r})=>{const{resetSelections:a}=k();return t.createElement(u,{onClose:()=>{a(),e()},size:n},t.createElement(g,null),t.createElement(C,null),t.createElement(E,{onTransactionComplete:r}))},S=({onClose:e,buttonSize:n,networkSelector:r,onTransactionComplete:a})=>t.createElement(w,{networkSelector:r},t.createElement(y,null,t.createElement(_,{onClose:e,buttonSize:n,onTransactionComplete:a})));return{NetworkSelector:class{constructor(e){this.merchantConfig=e,this.blacklist=e.getBlacklist(),this.availableNetworks=this.getAvailableNetworks(),this.selectedNetwork=null}getAvailableNetworks(){return Object.entries(a).reduce(((e,[t,n])=>(this.blacklist.includes(n.chainId)||(e[t]=n),e)),{})}selectNetwork(e){return null===e?(this.selectedNetwork=null,console.log("Network selection reset"),!0):this.availableNetworks[e]?(this.selectedNetwork=e,console.log(`Network selected: ${e}`),!0):(console.error(`Invalid network: ${e}`),!1)}getSelectedNetworkConfig(){return this.selectedNetwork?this.availableNetworks[this.selectedNetwork]:null}getReceivingAddress(){return this.merchantConfig.getReceivingAddress()}getTokenAmount(e){return this.merchantConfig.getTokenAmount(this.selectedNetwork,e)}},Transaction:i,Config:class{constructor(e={}){this.receivingAddress=e.receivingAddress||"",this.blacklist=e.blacklist||[],this.amounts=e.Amounts||{},this.validateConfig()}validateConfig(){if(!this.receivingAddress)throw new Error("Receiving address is required");for(const[e,t]of Object.entries(this.amounts)){if(!a[e])throw new Error(`Invalid network: ${e}`);if(!t.stablecoin||"number"!=typeof t.stablecoin||t.stablecoin<=0)throw new Error(`Invalid stablecoin amount for network ${e}`)}}getBlacklist(){return this.blacklist}getReceivingAddress(){return this.receivingAddress}getTokenAmount(e){console.log("Getting amount for network:",e),console.log("Amounts object:",this.amounts);const t=this.amounts[e]?.stablecoin;return console.log("Returning amount:",t),t||0}},Widget:({networkSelector:e,buttonSize:n="medium",onTransactionComplete:r,onSuccess:a})=>{const[i,o]=t.useState(!1),s=r||a;return t.createElement("div",{className:d.widgetContainer},!i&&t.createElement(l,{onClick:()=>{o(!0)},size:n}),i&&t.createElement(S,{onClose:()=>{o(!1)},buttonSize:n,networkSelector:e,onTransactionComplete:s}))},PayButton:l,Dialog:u,NetworkDropdown:g}})); +!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t(require("djed-sdk"),require("react"),require("viem"),require("viem/chains")):"function"==typeof define&&define.amd?define(["djed-sdk","react","viem","viem/chains"],t):(e="undefined"!=typeof globalThis?globalThis:e||self).StablePay=t(e.DjedSdk,e.React,e.viem,e.viemChains)}(this,(function(e,t,n,a){"use strict";const r={sepolia:{uri:"https://ethereum-sepolia.publicnode.com/",chainId:11155111,djedAddress:"0x624FcD0a1F9B5820c950FefD48087531d38387f4",tokens:{stablecoin:{symbol:"SOD",address:"0x6b930182787F346F18666D167e8d32166dC5eFBD",decimals:18,isDirectTransfer:!0},native:{symbol:"ETH",decimals:18,isNative:!0}},feeUI:0},"milkomeda-mainnet":{uri:"https://rpc-mainnet-cardano-evm.c1.milkomeda.com",chainId:2001,djedAddress:"0x67A30B399F5Ed499C1a6Bc0358FA6e42Ea4BCe76",tokens:{stablecoin:{symbol:"MOD",address:"0xcbA90fB1003b9D1bc6a2b66257D2585011b004e9",decimals:18,isDirectTransfer:!0},native:{symbol:"mADA",decimals:18,isNative:!0}},feeUI:0},"ethereum-classic":{uri:"https://etc.rivet.link",chainId:61,djedAddress:"0xCc3664d7021FD36B1Fe2b136e2324710c8442cCf",tokens:{stablecoin:{symbol:"ECSD",address:"0x5A7Ca94F6E969C94bef4CE5e2f90ed9d4891918A",decimals:18,isDirectTransfer:!0},native:{symbol:"ETC",decimals:18,isNative:!0}},feeUI:0}};var i=[{inputs:[{internalType:"string",name:"name",type:"string"},{internalType:"string",name:"symbol",type:"string"}],stateMutability:"nonpayable",type:"constructor"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"owner",type:"address"},{indexed:!0,internalType:"address",name:"spender",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Approval",type:"event"},{anonymous:!1,inputs:[{indexed:!0,internalType:"address",name:"from",type:"address"},{indexed:!0,internalType:"address",name:"to",type:"address"},{indexed:!1,internalType:"uint256",name:"value",type:"uint256"}],name:"Transfer",type:"event"},{inputs:[{internalType:"address",name:"owner",type:"address"},{internalType:"address",name:"spender",type:"address"}],name:"allowance",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"approve",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"account",type:"address"}],name:"balanceOf",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"subtractedValue",type:"uint256"}],name:"decreaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"spender",type:"address"},{internalType:"uint256",name:"addedValue",type:"uint256"}],name:"increaseAllowance",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"name",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"symbol",outputs:[{internalType:"string",name:"",type:"string"}],stateMutability:"view",type:"function"},{inputs:[],name:"totalSupply",outputs:[{internalType:"uint256",name:"",type:"uint256"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transferFrom",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"},{inputs:[],name:"decimals",outputs:[{internalType:"uint8",name:"",type:"uint8"}],stateMutability:"view",type:"function"},{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"mint",outputs:[],stateMutability:"nonpayable",type:"function"},{inputs:[{internalType:"address",name:"from",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"burn",outputs:[],stateMutability:"nonpayable",type:"function"}];class s{constructor(e,t,n=null){this.networkUri=e,this.djedAddress=t,this.baseAssetAddress=n}async init(){if(!this.networkUri||!this.djedAddress)throw new Error("Network URI and DJED address are required");try{this.web3=await e.getWeb3(this.networkUri),this.djedContract=e.getDjedContract(this.web3,this.djedAddress),this.baseAssetAddress&&(this.baseAssetContract=new this.web3.eth.Contract(i,this.baseAssetAddress));try{const{stableCoin:t,reserveCoin:n}=await e.getCoinContracts(this.djedContract,this.web3),{scDecimals:a,rcDecimals:r}=await e.getDecimals(t,n);this.stableCoin=t,this.reserveCoin=n,this.scDecimals=a,this.rcDecimals=r,this.oracleContract=await e.getOracleAddress(this.djedContract).then((t=>e.getOracleContract(this.web3,t,this.djedContract._address))),this.oracleAddress=this.oracleContract._address}catch(e){if(console.error("[Transaction] Error fetching contract details:",e),e.message&&e.message.includes("execution reverted")){const e=e=>e.includes("milkomeda")?{name:"Milkomeda",chainId:"2001"}:e.includes("mordor")?{name:"Mordor Testnet",chainId:"63"}:e.includes("sepolia")?{name:"Sepolia",chainId:"11155111"}:e.includes("etc.rivet.link")?{name:"Ethereum Classic",chainId:"61"}:{name:"the selected network",chainId:"unknown"},{name:t,chainId:n}=e(this.networkUri);throw new Error(`Failed to interact with Djed contract at ${this.djedAddress} on ${t}.\n\nPossible causes:\n- The contract address may be incorrect\n- The contract may not be deployed on ${t}\n- The contract may not be a valid Djed contract\n\nPlease verify the contract address is correct for ${t} (Chain ID: ${n}).`)}throw e}}catch(e){if(console.error("[Transaction] Error initializing transaction:",e),e.message&&(e.message.includes("CONNECTION ERROR")||e.message.includes("ERR_NAME_NOT_RESOLVED"))){const e=(e=>e.includes("milkomeda")?"Milkomeda":e.includes("mordor")?"Mordor":e.includes("sepolia")?"Sepolia":"the selected network")(this.networkUri);throw new Error(`Failed to connect to ${e} RPC endpoint: ${this.networkUri}\n\nPossible causes:\n- The RPC endpoint may be temporarily unavailable\n- DNS resolution issue (check your internet connection)\n- Network firewall blocking the connection\n\nPlease try again in a few moments or check the network status.`)}throw e}}getBlockchainDetails(){return{web3Available:!!this.web3,djedContractAvailable:!!this.djedContract,stableCoinAddress:this.stableCoin?this.stableCoin._address:"N/A",reserveCoinAddress:this.reserveCoin?this.reserveCoin._address:"N/A",stableCoinDecimals:this.scDecimals,reserveCoinDecimals:this.rcDecimals,oracleAddress:this.oracleAddress||"N/A",oracleContractAvailable:!!this.oracleContract}}async handleTradeDataBuySc(t){if(!this.djedContract)throw new Error("DJED contract is not initialized");if("string"!=typeof t)throw new Error("Amount must be a string");try{return(await e.tradeDataPriceBuySc(this.djedContract,this.scDecimals,t)).totalBCScaled}catch(e){throw console.error("Error fetching trade data for buying stablecoins: ",e),e}}async buyStablecoins(t,n,a){if(!this.djedContract)throw new Error("DJED contract is not initialized");try{const r="0x0232556C83791b8291E9b23BfEa7d67405Bd9839";if(this.baseAssetAddress){if(!this.baseAssetContract)throw new Error("Base Asset contract not initialized for ERC20 flow");return e.buyScIsisTx(this.djedContract,t,n,a,r,this.djedAddress)}return e.buyScTx(this.djedContract,t,n,a,r,this.djedAddress)}catch(e){throw console.error("Error executing buyStablecoins transaction: ",e),e}}async approveBaseAsset(t,n){if(!this.baseAssetContract)throw new Error("No Base Asset contract to approve");return e.approveTx(this.baseAssetContract,t,this.djedAddress,n)}async checkBaseAssetAllowance(t){return this.baseAssetContract?e.checkAllowance(this.baseAssetContract,t,this.djedAddress):"Inf"}}var o="main_stablePayButton__UA7HC",l="main_logo__ITyEy",c="main_buttonText__N-ewy";const d=({onClick:e,size:n="medium"})=>{const a={small:{width:"200px",height:"50px",fontSize:"14px"},medium:{width:"250px",height:"60px",fontSize:"16px"},large:{width:"300px",height:"70px",fontSize:"18px"}},r={small:{width:"35px",height:"33px"},medium:{width:"40px",height:"38px"},large:{width:"45px",height:"43px"}},i=a[n]||a.medium,s=r[n]||r.medium;return t.createElement("button",{className:o,onClick:e,style:i},t.createElement("div",{className:l,style:s}),t.createElement("span",{className:c},"Pay with StablePay"))};var u={dialogOverlay:"PricingCard_dialogOverlay__0XJrE",pricingCard:"PricingCard_pricingCard__LrWb9",small:"PricingCard_small__J4CHj",medium:"PricingCard_medium__EVmTB",large:"PricingCard_large__A6pnX",dialogClose:"PricingCard_dialogClose__jJ1tM",pricingCardHeader:"PricingCard_pricingCardHeader__wGczA",allianceLogo:"PricingCard_allianceLogo__URa-U",stablepayTitle:"PricingCard_stablepayTitle__4t848",pricingCardBody:"PricingCard_pricingCardBody__0wKQn",selectField:"PricingCard_selectField__LBPoZ",transactionReview:"PricingCard_transactionReview__Ix-eL",transactionInfo:"PricingCard_transactionInfo__Ck-Rc",transactionLabel:"PricingCard_transactionLabel__GDux7",transactionValue:"PricingCard_transactionValue__q-xxp",infoSection:"PricingCard_infoSection__gyjMQ",infoIcon:"PricingCard_infoIcon__rraxD",infoText:"PricingCard_infoText__l4b7A",walletButton:"PricingCard_walletButton__llw4v",loading:"PricingCard_loading__2-tGA",error:"PricingCard_error__m5fK-",networkError:"PricingCard_networkError__zR-36",errorText:"PricingCard_errorText__qZRJt","message-box":"PricingCard_message-box__vkUKy",detailsButton:"PricingCard_detailsButton__jHglL",errorDetails:"PricingCard_errorDetails__CzN-7",loadingContainer:"PricingCard_loadingContainer__6nOVa",spinner:"PricingCard_spinner__9ucQv",spin:"PricingCard_spin__24tni"};const m=({children:e,onClose:n,size:a="medium"})=>t.createElement("div",{className:u.dialogOverlay},t.createElement("div",{className:`${u.pricingCard} ${u[a]}`},t.createElement("button",{className:u.dialogClose,onClick:n},"×"),t.createElement("div",{className:u.pricingCardHeader},t.createElement("div",{className:u.allianceLogo}),t.createElement("h2",{className:u.stablepayTitle},"StablePay")),t.createElement("div",{className:u.pricingCardBody},e)));class h{constructor(e){this.networkSelector=e,this.selectedToken=null}selectToken(e){const t=this.networkSelector.getSelectedNetworkConfig();return!(!t||!t.tokens[e])&&(this.selectedToken={key:e,...t.tokens[e]},!0)}getSelectedToken(){return this.selectedToken}getAvailableTokens(){const e=this.networkSelector.getSelectedNetworkConfig();return e?Object.entries(e.tokens).map((([e,t])=>({key:e,...t}))):[]}resetSelection(){this.selectedToken=null}}const p=t.createContext(),w=({children:e,networkSelector:n})=>{const[a]=t.useState((()=>new h(n))),[r,i]=t.useState(null),[s,o]=t.useState(null),[l,c]=t.useState(null),d=()=>{o(null),c(null)};return t.useEffect((()=>{i(n.selectedNetwork)}),[n.selectedNetwork]),t.createElement(p.Provider,{value:{networkSelector:n,tokenSelector:a,selectedNetwork:r,selectedToken:s,transactionDetails:l,setTransactionDetails:c,selectNetwork:e=>!!n.selectNetwork(e)&&(i(e),d(),!0),selectToken:e=>{if(a.selectToken(e)){const e=a.getSelectedToken();return o(e),!0}return!1},resetSelections:()=>{n.selectNetwork(null),i(null),d()}}},e)},y=()=>{const e=t.useContext(p);if(void 0===e)throw new Error("useNetwork must be used within a NetworkProvider");return e},k=()=>{const{networkSelector:e,selectedNetwork:n,selectNetwork:a}=y();return t.createElement("div",{className:u.selectField},t.createElement("label",{htmlFor:"network-select"},"Select Network"),t.createElement("select",{id:"network-select",onChange:e=>{a(e.target.value)},value:n||""},t.createElement("option",{value:"",disabled:!0},"Select a network"),Object.keys(e.availableNetworks).map((e=>t.createElement("option",{key:e,value:e},e)))))},b=()=>{const{networkSelector:e,tokenSelector:n,selectedNetwork:a,selectedToken:r,selectToken:i,setTransactionDetails:o}=y(),[l,c]=t.useState(!1),[d,m]=t.useState(null),h=a?n.getAvailableTokens():[];return t.createElement("div",{className:u.selectField},t.createElement("label",{htmlFor:"token-select"},"Select Token"),t.createElement("select",{id:"token-select",onChange:async t=>{const r=t.target.value;m(null),c(!0);try{if(i(r)){const t=e.getSelectedNetworkConfig(),i=new s(t.uri,t.djedAddress);await i.init();const l=e.getTokenAmount(r),c=i.getBlockchainDetails();let d=null;"native"===r&&(d=await i.handleTradeDataBuySc(String(l))),o({network:a,token:r,tokenSymbol:n.getSelectedToken().symbol,amount:l,receivingAddress:e.getReceivingAddress(),djedContractAddress:t.djedAddress,isDirectTransfer:n.getSelectedToken().isDirectTransfer||!1,isNativeToken:n.getSelectedToken().isNative||!1,tradeAmount:d?d.amount:null,...c})}}catch(e){console.error("Error fetching transaction details:",e),m("Failed to fetch transaction details. Please try again.")}finally{c(!1)}},value:r?r.key:"",disabled:!a||l},t.createElement("option",{value:"",disabled:!0},a?l?"Loading...":"Select a token":"Please select a network first"),h.map((e=>t.createElement("option",{key:e.key,value:e.key},e.symbol," (",e.isDirectTransfer?"Direct Transfer":"Native",")")))),d&&t.createElement("div",{className:u.error},d))};n.defineChain({id:63,name:"Mordor Testnet",network:"mordor",nativeCurrency:{decimals:18,name:"Mordor Ether",symbol:"METC"},rpcUrls:{default:{http:["https://rpc.mordor.etccooperative.org"],webSocket:["wss://rpc.mordor.etccooperative.org/ws"]}},blockExplorers:{default:{name:"BlockScout",url:"https://blockscout.com/etc/mordor"}},testnet:!0});const g=n.defineChain({id:2001,name:"Milkomeda C1 Mainnet",network:"milkomeda",nativeCurrency:{decimals:18,name:"Milkomeda ADA",symbol:"mADA"},rpcUrls:{default:{http:["https://rpc-mainnet-cardano-evm.c1.milkomeda.com"]}},blockExplorers:{default:{name:"Milkomeda Explorer",url:"https://explorer-mainnet-cardano-evm.c1.milkomeda.com"}},testnet:!1}),C=n.defineChain({id:61,name:"Ethereum Classic",network:"etc",nativeCurrency:{decimals:18,name:"Ethereum Classic",symbol:"ETC"},rpcUrls:{default:{http:["https://etc.rivet.link"]}},blockExplorers:{default:{name:"Blockscout",url:"https://blockscout.com/etc/mainnet"}},testnet:!1}),f=t.createContext(null),v=async e=>{if(!window.ethereum)throw new Error("MetaMask not installed");const t=(e=>{switch(e){case"sepolia":return{chainId:`0x${a.sepolia.id.toString(16)}`,chainName:"Sepolia",nativeCurrency:{name:"Ether",symbol:"ETH",decimals:18},rpcUrls:a.sepolia.rpcUrls.default.http,blockExplorerUrls:a.sepolia.blockExplorers?.default?.url?[a.sepolia.blockExplorers.default.url]:[]};case"ethereum-classic":return{chainId:`0x${C.id.toString(16)}`,chainName:"Ethereum Classic",nativeCurrency:{name:"Ethereum Classic",symbol:"ETC",decimals:18},rpcUrls:["https://etc.rivet.link"],blockExplorerUrls:["https://blockscout.com/etc/mainnet"]};case"milkomeda-mainnet":return{chainId:`0x${g.id.toString(16)}`,chainName:"Milkomeda C1 Mainnet",nativeCurrency:{name:"Milkomeda ADA",symbol:"mADA",decimals:18},rpcUrls:["https://rpc-mainnet-cardano-evm.c1.milkomeda.com"],blockExplorerUrls:["https://explorer-mainnet-cardano-evm.c1.milkomeda.com"]};default:return null}})(e);if(!t)throw new Error(`Unsupported network: ${e}`);try{await window.ethereum.request({method:"wallet_switchEthereumChain",params:[{chainId:t.chainId}]})}catch(e){if(4902!==e.code)throw 4001===e.code?new Error(`User rejected switching to ${t.chainName}. Please switch manually in MetaMask.`):new Error(`Failed to switch to ${t.chainName}: ${e.message}`);try{await window.ethereum.request({method:"wallet_addEthereumChain",params:[t]})}catch(e){if(4001===e.code)throw new Error(`User rejected adding ${t.chainName} to MetaMask. Please add it manually.`);throw new Error(`Failed to add ${t.chainName} to MetaMask: ${e.message}`)}}},E=({children:e})=>{const{selectedNetwork:r}=y(),[i,s]=t.useState(null),[o,l]=t.useState(null),[c,d]=t.useState(null),[u,m]=t.useState(null),[h,p]=t.useState(null),[w,k]=t.useState(null),[b,E]=t.useState(!1),T=r?(e=>{switch(e){case"sepolia":return a.sepolia;case"ethereum-classic":return C;case"milkomeda-mainnet":return g;default:return null}})(r):null,_=T?T.id:null,S=t.useRef(null),N=t.useRef(null),A=t.useCallback((()=>{s(null),l(null),d(null),m(null),p(null),k(null)}),[]),x=t.useCallback((async e=>{const t=parseInt(e,16);if(m(t),T&&t===_){if(k(null),window.ethereum&&T){const e=n.createWalletClient({chain:T,transport:n.custom(window.ethereum)});s(e)}}else if(T&&t!==_){k(`Wrong network detected. Please switch to ${T?.name||r||"selected network"}`)}}),[T,_,r]);N.current=x;const D=t.useCallback((async e=>{if(0===e.length){if(A(),window.ethereum){const e=S.current,t=N.current;e&&window.ethereum.removeListener("accountsChanged",e),t&&window.ethereum.removeListener("chainChanged",t)}}else if(d(e[0]),T)try{const t=n.createPublicClient({chain:T,transport:n.http()});l(t);const a=await t.getBalance({address:e[0]});p(parseFloat(a)/Math.pow(10,18))}catch(e){console.error("Error fetching balance:",e),p(null)}}),[T,A]);S.current=D;const P=t.useCallback((()=>{if(A(),window.ethereum){const e=S.current,t=N.current;e&&window.ethereum.removeListener("accountsChanged",e),t&&window.ethereum.removeListener("chainChanged",t)}}),[A]),M=t.useCallback((()=>{T&&l(n.createPublicClient({chain:T,transport:n.http()}))}),[T]),I=t.useCallback((async()=>{if(!window.ethereum)return k("Please install MetaMask or another Web3 wallet"),!1;if(!r||!T)return k("Please select a network first"),!1;E(!0),k(null);try{const e=await window.ethereum.request({method:"eth_requestAccounts"});if(0===e.length)throw new Error("No wallet address found. Please unlock your wallet.");const t=await window.ethereum.request({method:"eth_chainId"});parseInt(t,16)!==_&&await v(r);const a=n.createWalletClient({chain:T,transport:n.custom(window.ethereum)});s(a),d(e[0]),m(_);const i=n.createPublicClient({chain:T,transport:n.http()});l(i);try{const t=await i.getBalance({address:e[0]});p(parseFloat(t)/Math.pow(10,18))}catch(e){console.error("Error fetching balance:",e),p(null)}return S.current=D,N.current=x,window.ethereum.on("accountsChanged",D),window.ethereum.on("chainChanged",x),!0}catch(e){return console.error("Error connecting wallet:",e),k(e.message),!1}finally{E(!1)}}),[r,T,_,D,x]),j=t.useCallback((async()=>{if(!(window.ethereum&&r&&T&&c)){return k("Wallet not connected or network not selected"),null}try{const e=await window.ethereum.request({method:"eth_chainId"});if(parseInt(e,16)!==_){k(null),await v(r);const e=500;await new Promise((t=>setTimeout(t,e)));const t=await window.ethereum.request({method:"eth_chainId"}),n=parseInt(t,16);if(n!==_)throw new Error(`Failed to switch network. MetaMask is still on chain ${n}, expected ${_}`)}const t=n.createWalletClient({chain:T,transport:n.custom(window.ethereum)});return s(t),m(_),k(null),t}catch(e){return k(e.message),null}}),[r,T,_,c]),B=t.useRef(r);return t.useEffect((()=>{if(null!==B.current&&B.current!==r&&c&&(A(),window.ethereum)){const e=S.current,t=N.current;e&&window.ethereum.removeListener("accountsChanged",e),t&&window.ethereum.removeListener("chainChanged",t)}B.current=r}),[r,c,A]),t.useEffect((()=>{M()}),[M]),t.createElement(f.Provider,{value:{walletClient:i,publicClient:o,account:c,chainId:u,balance:h,error:w,isConnecting:b,connectWallet:I,disconnectWallet:P,ensureCorrectNetwork:j,expectedChainId:_}},e)},T=({onTransactionComplete:e})=>{const{networkSelector:a,selectedNetwork:r,selectedToken:i,transactionDetails:o,setTransactionDetails:l}=y(),{connectWallet:c,account:d,walletClient:m,publicClient:h,isConnecting:p,ensureCorrectNetwork:w,expectedChainId:k}=(()=>{const e=t.useContext(f);if(!e)throw new Error("useWallet must be used within a WalletProvider");return e})(),[b,g]=t.useState(null),[C,v]=t.useState(null),[E,T]=t.useState(null),[_,S]=t.useState(""),[N,A]=t.useState(null),[x,D]=t.useState(null),[P,M]=t.useState(!1);if(t.useEffect((()=>{T(null),v(null),S(""),D(null),A(null)}),[r,i]),t.useEffect((()=>{(async()=>{if(r&&i)try{const e=a.getSelectedNetworkConfig(),t=a.getReceivingAddress(),n=a.getTokenAmount(i.key),o=new s(e.uri,e.djedAddress);await o.init(),g(o);let c=null;if("native"===i.key)try{c=await o.handleTradeDataBuySc(String(n)),v(c)}catch(e){console.error("Error fetching trade data:",e)}l({network:r,token:i.key,tokenSymbol:i.symbol,amount:n||"0",receivingAddress:t,djedContractAddress:e.djedAddress,isDirectTransfer:i.isDirectTransfer||!1,isNativeToken:i.isNative||!1,tradeAmount:c?c.amount:null,...o.getBlockchainDetails()})}catch(e){console.error("Error initializing transaction:",e)}})()}),[r,i,a,l]),!o)return t.createElement("div",{className:u.loading},"Initializing transaction...");const I=()=>{if(!N||!r)return null;const e={"ethereum-classic":"https://blockscout.com/etc/mainnet/tx/",sepolia:"https://sepolia.etherscan.io/tx/","milkomeda-mainnet":"https://explorer-mainnet-cardano-evm.c1.milkomeda.com/tx/"};return e[r]?`${e[r]}${N}`:null};return t.createElement("div",{className:u.transactionReview},t.createElement("div",{className:u.transactionInfo},t.createElement("span",{className:u.transactionLabel},"Network:"),t.createElement("span",{className:u.transactionValue},o.network)),t.createElement("div",{className:u.transactionInfo},t.createElement("span",{className:u.transactionLabel},"You Pay:"),t.createElement("span",{className:u.transactionValue},"stablecoin"===i.key?`${o.amount} ${o.tokenSymbol}`:`${C||"Calculating..."} ${o.tokenSymbol}`)),t.createElement("button",{className:u.walletButton,onClick:async()=>{await c()},disabled:p},p?"Connecting...":"Connect Wallet"),d&&!E&&t.createElement("button",{className:u.walletButton,onClick:async()=>{if(d&&o&&b)try{T(null),D(null),S("⏳ Preparing transaction...");const e=o.receivingAddress;let t;if("native"===i.key){const a="0x0232556C83791b8291E9b23BfEa7d67405Bd9839",r=C||"0",i=n.parseEther(String(r));t=await b.buyStablecoins(d,e,i,a),t={...t,value:i,account:d}}else{const r=a.getSelectedNetworkConfig(),i=r?.tokens?.stablecoin?.address;if(!i)throw new Error("Stablecoin address not found in network configuration");const s=o.amount?n.parseUnits(String(o.amount),o.stableCoinDecimals):"0";t={to:i,value:0n,data:n.encodeFunctionData({abi:[{inputs:[{internalType:"address",name:"to",type:"address"},{internalType:"uint256",name:"amount",type:"uint256"}],name:"transfer",outputs:[{internalType:"bool",name:"",type:"bool"}],stateMutability:"nonpayable",type:"function"}],functionName:"transfer",args:[e,s]}),account:d}}T(t),S("✅ Transaction ready! Click 'Send Transaction' to proceed.")}catch(e){D(e),S("❌ Transaction preparation failed.")}else S("❌ Wallet not connected or transaction details missing")}},"Prepare Transaction"),d&&E&&t.createElement("button",{className:u.walletButton,onClick:async()=>{D(null);try{if(!d||!E)return void S("❌ Wallet account or transaction data is missing");if(!r)return void S("❌ Network not selected");const t=a.getSelectedNetworkConfig();if(!t)return void S("❌ Network configuration not found");S("⏳ Verifying network...");const n=await w();if(!n)return void S("❌ Failed to switch to correct network. Please approve the network switch in MetaMask and try again.");if(!window.ethereum)return void S("❌ MetaMask not available");const s=await window.ethereum.request({method:"eth_chainId"}),l=parseInt(s,16);if(l!==t.chainId){const e=`Network mismatch. MetaMask is on chain ${l}, but ${r} requires chain ${t.chainId}. Please switch networks in MetaMask.`;return S(`❌ ${e}`),void D(new Error(e))}if(n.chain.id!==t.chainId){const e=`Wallet client chain mismatch. Wallet client is on chain ${n.chain.id}, but expected ${t.chainId}.`;return S(`❌ ${e}`),void D(new Error(e))}S("⏳ Sending transaction...");const c=await n.sendTransaction({...E,account:d});A(c),S("✅ Transaction sent!"),e&&e({txHash:c,network:r,token:i?.key,tokenSymbol:i?.symbol,amount:o?.amount,receivingAddress:o?.receivingAddress})}catch(e){D(e),S("❌ Transaction failed."),console.error("Transaction error:",e)}},disabled:null!==N},"Send Transaction"),_&&t.createElement("div",{className:"message-box"},_,x&&t.createElement("button",{onClick:()=>M(!P),className:u.detailsButton},P?"Hide Details":"Show Details")),P&&x&&t.createElement("div",{className:u.errorDetails},t.createElement("pre",null,x.message)),N&&t.createElement("div",{className:u.transactionLink},"✅ Transaction Hash:"," ",I()?t.createElement("a",{href:I(),target:"_blank",rel:"noopener noreferrer",className:u.explorerLink,style:{color:"#007bff",textDecoration:"underline",fontWeight:"bold",cursor:"pointer",wordBreak:"break-word"}},N.slice(0,6),"...",N.slice(-6)):t.createElement("span",{style:{wordBreak:"break-word"}},N)))},_=({onClose:e,buttonSize:n,onTransactionComplete:a})=>{const{resetSelections:r}=y();return t.createElement(m,{onClose:()=>{r(),e()},size:n},t.createElement(k,null),t.createElement(b,null),t.createElement(T,{onTransactionComplete:a}))},S=({onClose:e,buttonSize:n,networkSelector:a,onTransactionComplete:r})=>t.createElement(w,{networkSelector:a},t.createElement(E,null,t.createElement(_,{onClose:e,buttonSize:n,onTransactionComplete:r})));return{NetworkSelector:class{constructor(e){this.merchantConfig=e,this.blacklist=e.getBlacklist(),this.availableNetworks=this.getAvailableNetworks(),this.selectedNetwork=null}getAvailableNetworks(){return Object.entries(r).reduce(((e,[t,n])=>(this.blacklist.includes(n.chainId)||(e[t]=n),e)),{})}selectNetwork(e){return null===e?(this.selectedNetwork=null,console.log("Network selection reset"),!0):this.availableNetworks[e]?(this.selectedNetwork=e,console.log(`Network selected: ${e}`),!0):(console.error(`Invalid network: ${e}`),!1)}getSelectedNetworkConfig(){return this.selectedNetwork?this.availableNetworks[this.selectedNetwork]:null}getReceivingAddress(){return this.merchantConfig.getReceivingAddress()}getTokenAmount(e){return this.merchantConfig.getTokenAmount(this.selectedNetwork,e)}},Transaction:s,Config:class{constructor(e={}){this.receivingAddress=e.receivingAddress||"",this.blacklist=e.blacklist||[],this.amounts=e.Amounts||{},this.validateConfig()}validateConfig(){if(!this.receivingAddress)throw new Error("Receiving address is required");for(const[e,t]of Object.entries(this.amounts)){if(!r[e])throw new Error(`Invalid network: ${e}`);if(!t.stablecoin||"number"!=typeof t.stablecoin||t.stablecoin<=0)throw new Error(`Invalid stablecoin amount for network ${e}`)}}getBlacklist(){return this.blacklist}getReceivingAddress(){return this.receivingAddress}getTokenAmount(e){console.log("Getting amount for network:",e),console.log("Amounts object:",this.amounts);const t=this.amounts[e]?.stablecoin;return console.log("Returning amount:",t),t||0}},Widget:({networkSelector:e,buttonSize:n="medium",onTransactionComplete:a,onSuccess:r})=>{const[i,s]=t.useState(!1),o=a||r;return t.createElement("div",{className:u.widgetContainer},!i&&t.createElement(d,{onClick:()=>{s(!0)},size:n}),i&&t.createElement(S,{onClose:()=>{s(!1)},buttonSize:n,networkSelector:e,onTransactionComplete:o}))},PayButton:d,Dialog:m,NetworkDropdown:k}})); //# sourceMappingURL=index.js.map diff --git a/stablepay-sdk/dist/umd/index.js.map b/stablepay-sdk/dist/umd/index.js.map index f7c2fad..738f175 100644 --- a/stablepay-sdk/dist/umd/index.js.map +++ b/stablepay-sdk/dist/umd/index.js.map @@ -1 +1 @@ -{"version":3,"file":"index.js","sources":["../../src/utils/config.js","../../src/core/Transaction.js","../../src/widget/PayButton.jsx","../../src/widget/Dialog.jsx","../../src/core/TokenSelector.js","../../src/contexts/NetworkContext.jsx","../../src/widget/NetworkDropdown.jsx","../../src/widget/TokenDropdown.jsx","../../src/contexts/chains.js","../../src/contexts/WalletContext.jsx","../../src/widget/TransactionReview.jsx","../../src/widget/Widget.jsx","../../src/index.js","../../src/core/NetworkSelector.js","../../src/core/MerchantConfig.js"],"sourcesContent":["// src/utils/config.js\nexport const networksConfig = {\n 'sepolia': {\n uri: 'https://ethereum-sepolia.publicnode.com/',\n chainId: 11155111,\n djedAddress: '0x624FcD0a1F9B5820c950FefD48087531d38387f4',\n tokens: {\n stablecoin: {\n symbol: 'SOD',\n address: '0x6b930182787F346F18666D167e8d32166dC5eFBD',\n decimals: 18,\n isDirectTransfer: true\n },\n native: {\n symbol: 'ETH',\n decimals: 18,\n isNative: true\n }\n },\n feeUI: 0\n },\n 'milkomeda-mainnet': {\n uri: 'https://rpc-mainnet-cardano-evm.c1.milkomeda.com',\n chainId: 2001,\n djedAddress: '0x67A30B399F5Ed499C1a6Bc0358FA6e42Ea4BCe76',\n tokens: {\n stablecoin: {\n symbol: 'MOD',\n address: '0xcbA90fB1003b9D1bc6a2b66257D2585011b004e9',\n decimals: 18,\n isDirectTransfer: true\n },\n native: {\n symbol: 'mADA',\n decimals: 18,\n isNative: true\n }\n },\n feeUI: 0\n },\n 'ethereum-classic': {\n uri: 'https://etc.rivet.link',\n chainId: 61,\n djedAddress: '0xCc3664d7021FD36B1Fe2b136e2324710c8442cCf',\n tokens: {\n stablecoin: {\n symbol: 'ECSD',\n address: '0x5A7Ca94F6E969C94bef4CE5e2f90ed9d4891918A',\n decimals: 18,\n isDirectTransfer: true\n },\n native: {\n symbol: 'ETC',\n decimals: 18,\n isNative: true\n }\n },\n feeUI: 0\n }\n};","import { getWeb3, getDjedContract, getCoinContracts, getDecimals, getOracleAddress, getOracleContract, tradeDataPriceBuySc, buyScTx } from 'djed-sdk';\n\nexport class Transaction {\n constructor(networkUri, djedAddress) {\n this.networkUri = networkUri;\n this.djedAddress = djedAddress;\n }\n\n async init() {\n if (!this.networkUri || !this.djedAddress) {\n throw new Error('Network URI and DJED address are required');\n }\n\n try {\n this.web3 = await getWeb3(this.networkUri);\n this.djedContract = getDjedContract(this.web3, this.djedAddress);\n \n try {\n const { stableCoin, reserveCoin } = await getCoinContracts(this.djedContract, this.web3);\n const { scDecimals, rcDecimals } = await getDecimals(stableCoin, reserveCoin);\n this.stableCoin = stableCoin;\n this.reserveCoin = reserveCoin;\n this.scDecimals = scDecimals;\n this.rcDecimals = rcDecimals;\n\n this.oracleContract = await getOracleAddress(this.djedContract).then((addr) =>\n getOracleContract(this.web3, addr, this.djedContract._address)\n );\n\n this.oracleAddress = this.oracleContract._address;\n } catch (contractError) {\n console.error('[Transaction] Error fetching contract details:', contractError);\n if (contractError.message && contractError.message.includes('execution reverted')) {\n const getNetworkInfo = (uri) => {\n if (uri.includes('milkomeda')) return { name: 'Milkomeda', chainId: '2001' };\n if (uri.includes('mordor')) return { name: 'Mordor Testnet', chainId: '63' };\n if (uri.includes('sepolia')) return { name: 'Sepolia', chainId: '11155111' };\n if (uri.includes('etc.rivet.link')) return { name: 'Ethereum Classic', chainId: '61' };\n return { name: 'the selected network', chainId: 'unknown' };\n };\n const { name: networkName, chainId } = getNetworkInfo(this.networkUri);\n throw new Error(\n `Failed to interact with Djed contract at ${this.djedAddress} on ${networkName}.\\n\\n` +\n `Possible causes:\\n` +\n `- The contract address may be incorrect\\n` +\n `- The contract may not be deployed on ${networkName}\\n` +\n `- The contract may not be a valid Djed contract\\n\\n` +\n `Please verify the contract address is correct for ${networkName} (Chain ID: ${chainId}).`\n );\n }\n throw contractError;\n }\n } catch (error) {\n console.error('[Transaction] Error initializing transaction:', error);\n if (error.message && (error.message.includes('CONNECTION ERROR') || error.message.includes('ERR_NAME_NOT_RESOLVED'))) {\n const getNetworkName = (uri) => {\n if (uri.includes('milkomeda')) return 'Milkomeda';\n if (uri.includes('mordor')) return 'Mordor';\n if (uri.includes('sepolia')) return 'Sepolia';\n return 'the selected network';\n };\n const networkName = getNetworkName(this.networkUri);\n throw new Error(\n `Failed to connect to ${networkName} RPC endpoint: ${this.networkUri}\\n\\n` +\n `Possible causes:\\n` +\n `- The RPC endpoint may be temporarily unavailable\\n` +\n `- DNS resolution issue (check your internet connection)\\n` +\n `- Network firewall blocking the connection\\n\\n` +\n `Please try again in a few moments or check the network status.`\n );\n }\n throw error;\n }\n }\n\n getBlockchainDetails() {\n return {\n web3Available: !!this.web3,\n djedContractAvailable: !!this.djedContract,\n stableCoinAddress: this.stableCoin ? this.stableCoin._address : 'N/A',\n reserveCoinAddress: this.reserveCoin ? this.reserveCoin._address : 'N/A',\n stableCoinDecimals: this.scDecimals,\n reserveCoinDecimals: this.rcDecimals,\n oracleAddress: this.oracleAddress || 'N/A',\n oracleContractAvailable: !!this.oracleContract,\n };\n }\n\n async handleTradeDataBuySc(amountScaled) {\n if (!this.djedContract) {\n throw new Error(\"DJED contract is not initialized\");\n }\n if (typeof amountScaled !== 'string') {\n throw new Error(\"Amount must be a string\");\n }\n try {\n const result = await tradeDataPriceBuySc(this.djedContract, this.scDecimals, amountScaled);\n return result.totalBCScaled;\n } catch (error) {\n console.error(\"Error fetching trade data for buying stablecoins: \", error);\n throw error;\n }\n }\n\n async buyStablecoins(payer, receiver, value) {\n if (!this.djedContract) {\n throw new Error(\"DJED contract is not initialized\");\n }\n try {\n const UI = '0x0232556C83791b8291E9b23BfEa7d67405Bd9839';\n\n const txData = await buyScTx(this.djedContract, payer, receiver, value, UI, this.djedAddress);\n\n return txData;\n } catch (error) {\n console.error(\"Error executing buyStablecoins transaction: \", error);\n throw error;\n }\n }\n}\n","import React from \"react\";\nimport styles from \"../styles/main.css\";\n\nconst PayButton = ({ onClick, size = \"medium\" }) => {\n const sizeStyles = {\n small: { width: \"200px\", height: \"50px\", fontSize: \"14px\" },\n medium: { width: \"250px\", height: \"60px\", fontSize: \"16px\" },\n large: { width: \"300px\", height: \"70px\", fontSize: \"18px\" },\n };\n\n const logoSizes = {\n small: { width: \"35px\", height: \"33px\" },\n medium: { width: \"40px\", height: \"38px\" },\n large: { width: \"45px\", height: \"43px\" },\n };\n\n const buttonStyle = sizeStyles[size] || sizeStyles.medium;\n const logoStyle = logoSizes[size] || logoSizes.medium;\n\n return (\n \n
\n Pay with StablePay\n \n );\n};\n\nexport default PayButton;\n","import React from 'react';\nimport styles from '../styles/PricingCard.css';\n\n\nconst Dialog = ({ children, onClose, size = 'medium' }) => {\n return (\n
\n
\n \n
\n
\n\n

StablePay

\n
\n
\n {children}\n
\n
\n
\n );\n};\n\nexport default Dialog;","// TokenSelector.js\n\nexport class TokenSelector {\n constructor(networkSelector) {\n this.networkSelector = networkSelector;\n this.selectedToken = null;\n }\n\n selectToken(tokenKey) {\n const networkConfig = this.networkSelector.getSelectedNetworkConfig();\n if (networkConfig && networkConfig.tokens[tokenKey]) {\n this.selectedToken = {\n key: tokenKey,\n ...networkConfig.tokens[tokenKey]\n };\n return true;\n }\n return false;\n }\n\n getSelectedToken() {\n return this.selectedToken;\n }\n\n getAvailableTokens() {\n const networkConfig = this.networkSelector.getSelectedNetworkConfig();\n if (!networkConfig) return [];\n\n return Object.entries(networkConfig.tokens).map(([key, config]) => ({\n key,\n ...config\n }));\n }\n\n resetSelection() {\n this.selectedToken = null;\n }\n}","import React, { createContext, useState, useContext, useEffect } from 'react';\nimport { TokenSelector } from '../core/TokenSelector';\n\nconst NetworkContext = createContext();\n\nexport const NetworkProvider = ({ children, networkSelector }) => {\n const [tokenSelector] = useState(() => new TokenSelector(networkSelector));\n const [selectedNetwork, setSelectedNetwork] = useState(null);\n const [selectedToken, setSelectedToken] = useState(null);\n const [transactionDetails, setTransactionDetails] = useState(null);\n\n const resetState = () => {\n setSelectedToken(null);\n setTransactionDetails(null);\n };\n\n const selectNetwork = (networkKey) => {\n if (networkSelector.selectNetwork(networkKey)) {\n setSelectedNetwork(networkKey);\n resetState(); \n return true;\n }\n return false;\n };\n\n const selectToken = (tokenKey) => {\n if (tokenSelector.selectToken(tokenKey)) {\n const token = tokenSelector.getSelectedToken();\n setSelectedToken(token);\n return true;\n }\n return false;\n };\n\n const resetSelections = () => {\n networkSelector.selectNetwork(null);\n setSelectedNetwork(null);\n resetState();\n };\n\n // Synchronize context state with NetworkSelector\n useEffect(() => {\n setSelectedNetwork(networkSelector.selectedNetwork);\n }, [networkSelector.selectedNetwork]);\n\n return (\n \n {children}\n \n );\n};\n\nexport const useNetwork = () => {\n const context = useContext(NetworkContext);\n if (context === undefined) {\n throw new Error('useNetwork must be used within a NetworkProvider');\n }\n return context;\n};\n\nexport default NetworkContext;","import React from 'react';\nimport { useNetwork } from '../contexts/NetworkContext';\nimport styles from '../styles/PricingCard.css';\n\nconst NetworkDropdown = () => {\n const { networkSelector, selectedNetwork, selectNetwork } = useNetwork();\n\n const handleNetworkChange = (event) => {\n selectNetwork(event.target.value);\n };\n\n return (\n
\n \n \n
\n );\n};\n\nexport default NetworkDropdown;","import React, { useState } from \"react\";\nimport { useNetwork } from \"../contexts/NetworkContext\";\nimport { Transaction } from \"../core/Transaction\";\nimport styles from \"../styles/PricingCard.css\";\n\nconst TokenDropdown = () => {\n const {\n networkSelector,\n tokenSelector,\n selectedNetwork,\n selectedToken,\n selectToken,\n setTransactionDetails,\n } = useNetwork();\n\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState(null);\n\n const handleTokenChange = async (event) => {\n const newValue = event.target.value;\n setError(null);\n setLoading(true);\n\n try {\n if (selectToken(newValue)) {\n const networkConfig = networkSelector.getSelectedNetworkConfig();\n const transaction = new Transaction(\n networkConfig.uri,\n networkConfig.djedAddress\n );\n await transaction.init();\n\n const tokenAmount = networkSelector.getTokenAmount(newValue);\n const blockchainDetails = transaction.getBlockchainDetails();\n\n let tradeData = null;\n if (newValue === \"native\") {\n tradeData = await transaction.handleTradeDataBuySc(\n String(tokenAmount)\n );\n }\n\n setTransactionDetails({\n network: selectedNetwork,\n token: newValue,\n tokenSymbol: tokenSelector.getSelectedToken().symbol,\n amount: tokenAmount,\n receivingAddress: networkSelector.getReceivingAddress(),\n djedContractAddress: networkConfig.djedAddress,\n isDirectTransfer:\n tokenSelector.getSelectedToken().isDirectTransfer || false,\n isNativeToken: tokenSelector.getSelectedToken().isNative || false,\n tradeAmount: tradeData ? tradeData.amount : null,\n ...blockchainDetails,\n });\n }\n } catch (err) {\n console.error(\"Error fetching transaction details:\", err);\n setError(\"Failed to fetch transaction details. Please try again.\");\n } finally {\n setLoading(false);\n }\n };\n\n const availableTokens = selectedNetwork\n ? tokenSelector.getAvailableTokens()\n : [];\n\n return (\n
\n \n \n \n {availableTokens.map((token) => (\n \n ))}\n \n {error &&
{error}
}\n
\n );\n};\n\nexport default TokenDropdown;\n","import { defineChain } from 'viem';\nimport { sepolia } from 'viem/chains';\n\nexport const mordor = defineChain({\n id: 63,\n name: 'Mordor Testnet',\n network: 'mordor',\n nativeCurrency: {\n decimals: 18,\n name: 'Mordor Ether',\n symbol: 'METC',\n },\n rpcUrls: {\n default: {\n http: ['https://rpc.mordor.etccooperative.org'],\n webSocket: ['wss://rpc.mordor.etccooperative.org/ws'],\n },\n },\n blockExplorers: {\n default: { name: 'BlockScout', url: 'https://blockscout.com/etc/mordor' },\n },\n testnet: true,\n});\n\nexport const milkomeda = defineChain({\n id: 2001,\n name: 'Milkomeda C1 Mainnet',\n network: 'milkomeda',\n nativeCurrency: {\n decimals: 18,\n name: 'Milkomeda ADA',\n symbol: 'mADA',\n },\n rpcUrls: {\n default: {\n http: ['https://rpc-mainnet-cardano-evm.c1.milkomeda.com'],\n },\n },\n blockExplorers: {\n default: { name: 'Milkomeda Explorer', url: 'https://explorer-mainnet-cardano-evm.c1.milkomeda.com' },\n },\n testnet: false,\n});\n\nexport const etcMainnet = defineChain({\n id: 61,\n name: 'Ethereum Classic',\n network: 'etc',\n nativeCurrency: {\n decimals: 18,\n name: 'Ethereum Classic',\n symbol: 'ETC',\n },\n rpcUrls: {\n default: {\n http: ['https://etc.rivet.link'],\n },\n },\n blockExplorers: {\n default: { name: 'Blockscout', url: 'https://blockscout.com/etc/mainnet' },\n },\n testnet: false,\n});\n\nexport const getChainByNetworkKey = (networkKey) => {\n switch (networkKey) {\n case 'sepolia':\n return sepolia;\n case 'ethereum-classic':\n return etcMainnet;\n case 'milkomeda-mainnet':\n return milkomeda;\n default:\n return null;\n }\n};\n\nexport const getChainConfigForWallet = (networkKey) => {\n switch (networkKey) {\n case 'sepolia':\n return {\n chainId: `0x${sepolia.id.toString(16)}`,\n chainName: 'Sepolia',\n nativeCurrency: {\n name: 'Ether',\n symbol: 'ETH',\n decimals: 18,\n },\n rpcUrls: sepolia.rpcUrls.default.http,\n blockExplorerUrls: sepolia.blockExplorers?.default?.url ? [sepolia.blockExplorers.default.url] : [],\n };\n case 'ethereum-classic':\n return {\n chainId: `0x${etcMainnet.id.toString(16)}`,\n chainName: 'Ethereum Classic',\n nativeCurrency: {\n name: 'Ethereum Classic',\n symbol: 'ETC',\n decimals: 18,\n },\n rpcUrls: ['https://etc.rivet.link'],\n blockExplorerUrls: ['https://blockscout.com/etc/mainnet'],\n };\n case 'milkomeda-mainnet':\n return {\n chainId: `0x${milkomeda.id.toString(16)}`,\n chainName: 'Milkomeda C1 Mainnet',\n nativeCurrency: {\n name: 'Milkomeda ADA',\n symbol: 'mADA',\n decimals: 18,\n },\n rpcUrls: ['https://rpc-mainnet-cardano-evm.c1.milkomeda.com'],\n blockExplorerUrls: ['https://explorer-mainnet-cardano-evm.c1.milkomeda.com'],\n };\n default:\n return null;\n }\n};\n","import React, { createContext, useContext, useState, useCallback, useEffect, useRef } from 'react';\nimport { createWalletClient, createPublicClient, custom, http } from 'viem';\nimport { useNetwork } from './NetworkContext';\nimport { getChainByNetworkKey, getChainConfigForWallet } from './chains';\n\nconst WalletContext = createContext(null);\n\nexport const useWallet = () => {\n const context = useContext(WalletContext);\n if (!context) {\n throw new Error('useWallet must be used within a WalletProvider');\n }\n return context;\n};\n\nconst switchToNetwork = async (networkKey) => {\n if (!window.ethereum) {\n throw new Error('MetaMask not installed');\n }\n\n const chainConfig = getChainConfigForWallet(networkKey);\n if (!chainConfig) {\n throw new Error(`Unsupported network: ${networkKey}`);\n }\n\n try {\n await window.ethereum.request({\n method: 'wallet_switchEthereumChain',\n params: [{ chainId: chainConfig.chainId }],\n });\n } catch (switchError) {\n if (switchError.code === 4902) {\n try {\n await window.ethereum.request({\n method: 'wallet_addEthereumChain',\n params: [chainConfig],\n });\n } catch (addError) {\n if (addError.code === 4001) {\n throw new Error(`User rejected adding ${chainConfig.chainName} to MetaMask. Please add it manually.`);\n }\n throw new Error(`Failed to add ${chainConfig.chainName} to MetaMask: ${addError.message}`);\n }\n } else if (switchError.code === 4001) {\n throw new Error(`User rejected switching to ${chainConfig.chainName}. Please switch manually in MetaMask.`);\n } else {\n throw new Error(`Failed to switch to ${chainConfig.chainName}: ${switchError.message}`);\n }\n }\n};\n\nexport const WalletProvider = ({ children }) => {\n const { selectedNetwork } = useNetwork();\n const [walletClient, setWalletClient] = useState(null);\n const [publicClient, setPublicClient] = useState(null);\n const [account, setAccount] = useState(null);\n const [chainId, setChainId] = useState(null);\n const [balance, setBalance] = useState(null);\n const [error, setError] = useState(null);\n const [isConnecting, setIsConnecting] = useState(false);\n\n const selectedChain = selectedNetwork ? getChainByNetworkKey(selectedNetwork) : null;\n const expectedChainId = selectedChain ? selectedChain.id : null;\n\n const handleAccountsChangedRef = useRef(null);\n const handleChainChangedRef = useRef(null);\n\n const disconnectWalletInternal = useCallback(() => {\n setWalletClient(null);\n setPublicClient(null);\n setAccount(null);\n setChainId(null);\n setBalance(null);\n setError(null);\n }, []);\n\n const handleChainChanged = useCallback(async (chainIdHex) => {\n const newChainId = parseInt(chainIdHex, 16);\n setChainId(newChainId);\n\n if (selectedChain && newChainId === expectedChainId) {\n setError(null);\n if (window.ethereum && selectedChain) {\n const newWalletClient = createWalletClient({ \n chain: selectedChain, \n transport: custom(window.ethereum) \n });\n setWalletClient(newWalletClient);\n }\n } else if (selectedChain && newChainId !== expectedChainId) {\n const chainName = selectedChain?.name || selectedNetwork || 'selected network';\n setError(`Wrong network detected. Please switch to ${chainName}`);\n }\n }, [selectedChain, expectedChainId, selectedNetwork]);\n\n handleChainChangedRef.current = handleChainChanged;\n\n const handleAccountsChanged = useCallback(async (accounts) => {\n if (accounts.length === 0) {\n disconnectWalletInternal();\n if (window.ethereum) {\n const accountsHandler = handleAccountsChangedRef.current;\n const chainHandler = handleChainChangedRef.current;\n if (accountsHandler) {\n window.ethereum.removeListener('accountsChanged', accountsHandler);\n }\n if (chainHandler) {\n window.ethereum.removeListener('chainChanged', chainHandler);\n }\n }\n } else {\n setAccount(accounts[0]);\n if (selectedChain) {\n try {\n const newPublicClient = createPublicClient({ chain: selectedChain, transport: http() });\n setPublicClient(newPublicClient);\n const balance = await newPublicClient.getBalance({ address: accounts[0] });\n setBalance(parseFloat(balance) / Math.pow(10, 18));\n } catch (error) {\n console.error('Error fetching balance:', error);\n setBalance(null);\n }\n }\n }\n }, [selectedChain, disconnectWalletInternal]);\n\n handleAccountsChangedRef.current = handleAccountsChanged;\n\n const disconnectWallet = useCallback(() => {\n disconnectWalletInternal();\n if (window.ethereum) {\n const accountsHandler = handleAccountsChangedRef.current;\n const chainHandler = handleChainChangedRef.current;\n if (accountsHandler) {\n window.ethereum.removeListener('accountsChanged', accountsHandler);\n }\n if (chainHandler) {\n window.ethereum.removeListener('chainChanged', chainHandler);\n }\n }\n }, [disconnectWalletInternal]);\n\n const connectPublicClient = useCallback(() => {\n if (selectedChain) {\n setPublicClient(createPublicClient({ chain: selectedChain, transport: http() }));\n }\n }, [selectedChain]);\n\n const connectWallet = useCallback(async () => {\n if (!window.ethereum) {\n setError('Please install MetaMask or another Web3 wallet');\n return false;\n }\n\n if (!selectedNetwork || !selectedChain) {\n setError('Please select a network first');\n return false;\n }\n\n setIsConnecting(true);\n setError(null);\n\n try {\n const accounts = await window.ethereum.request({ \n method: 'eth_requestAccounts' \n });\n\n if (accounts.length === 0) {\n throw new Error('No wallet address found. Please unlock your wallet.');\n }\n\n const chainIdHex = await window.ethereum.request({ method: 'eth_chainId' });\n const currentChainId = parseInt(chainIdHex, 16);\n\n if (currentChainId !== expectedChainId) {\n await switchToNetwork(selectedNetwork);\n }\n\n const newWalletClient = createWalletClient({\n chain: selectedChain,\n transport: custom(window.ethereum),\n });\n\n setWalletClient(newWalletClient);\n setAccount(accounts[0]);\n setChainId(expectedChainId);\n\n const newPublicClient = createPublicClient({ chain: selectedChain, transport: http() });\n setPublicClient(newPublicClient);\n try {\n const balance = await newPublicClient.getBalance({ address: accounts[0] });\n setBalance(parseFloat(balance) / Math.pow(10, 18));\n } catch (error) {\n console.error('Error fetching balance:', error);\n setBalance(null);\n }\n\n handleAccountsChangedRef.current = handleAccountsChanged;\n handleChainChangedRef.current = handleChainChanged;\n window.ethereum.on('accountsChanged', handleAccountsChanged);\n window.ethereum.on('chainChanged', handleChainChanged);\n\n return true;\n } catch (err) {\n console.error('Error connecting wallet:', err);\n setError(err.message);\n return false;\n } finally {\n setIsConnecting(false);\n }\n }, [selectedNetwork, selectedChain, expectedChainId, handleAccountsChanged, handleChainChanged]);\n\n const ensureCorrectNetwork = useCallback(async () => {\n if (!window.ethereum || !selectedNetwork || !selectedChain || !account) {\n const errorMsg = 'Wallet not connected or network not selected';\n setError(errorMsg);\n return null;\n }\n\n try {\n const chainIdHex = await window.ethereum.request({ method: 'eth_chainId' });\n const currentChainId = parseInt(chainIdHex, 16);\n\n if (currentChainId !== expectedChainId) {\n setError(null);\n await switchToNetwork(selectedNetwork);\n const NETWORK_SWITCH_DELAY_MS = 500;\n await new Promise(resolve => setTimeout(resolve, NETWORK_SWITCH_DELAY_MS));\n \n const newChainIdHex = await window.ethereum.request({ method: 'eth_chainId' });\n const newChainId = parseInt(newChainIdHex, 16);\n if (newChainId !== expectedChainId) {\n throw new Error(`Failed to switch network. MetaMask is still on chain ${newChainId}, expected ${expectedChainId}`);\n }\n }\n\n const freshWalletClient = createWalletClient({\n chain: selectedChain,\n transport: custom(window.ethereum),\n });\n\n setWalletClient(freshWalletClient);\n setChainId(expectedChainId);\n setError(null);\n return freshWalletClient;\n } catch (err) {\n setError(err.message);\n return null;\n }\n }, [selectedNetwork, selectedChain, expectedChainId, account]);\n\n const prevNetworkRef = useRef(selectedNetwork);\n\n useEffect(() => {\n if (prevNetworkRef.current !== null && \n prevNetworkRef.current !== selectedNetwork && \n account) {\n disconnectWalletInternal();\n if (window.ethereum) {\n const accountsHandler = handleAccountsChangedRef.current;\n const chainHandler = handleChainChangedRef.current;\n if (accountsHandler) {\n window.ethereum.removeListener('accountsChanged', accountsHandler);\n }\n if (chainHandler) {\n window.ethereum.removeListener('chainChanged', chainHandler);\n }\n }\n }\n prevNetworkRef.current = selectedNetwork;\n }, [selectedNetwork, account, disconnectWalletInternal]);\n\n useEffect(() => {\n connectPublicClient();\n }, [connectPublicClient]);\n\n return (\n \n {children}\n \n );\n};","import React, { useState, useEffect } from \"react\";\nimport { useNetwork } from \"../contexts/NetworkContext\";\nimport { useWallet } from \"../contexts/WalletContext\";\nimport { Transaction } from \"../core/Transaction\";\nimport { parseEther, encodeFunctionData, parseUnits } from \"viem\"; \nimport styles from \"../styles/PricingCard.css\"; \n\nconst TransactionReview = ({ onTransactionComplete }) => {\n const {\n networkSelector,\n selectedNetwork,\n selectedToken,\n transactionDetails: contextTransactionDetails,\n setTransactionDetails,\n } = useNetwork();\n\n const {\n connectWallet,\n account,\n walletClient,\n publicClient,\n isConnecting,\n ensureCorrectNetwork,\n expectedChainId,\n } = useWallet();\n\n const [transaction, setTransaction] = useState(null);\n const [tradeDataBuySc, setTradeDataBuySc] = useState(null);\n const [txData, setTxData] = useState(null);\n const [message, setMessage] = useState(\"\");\n const [txHash, setTxHash] = useState(null);\n const [error, setError] = useState(null);\n const [isErrorDetailsVisible, setIsErrorDetailsVisible] = useState(false);\n\n useEffect(() => {\n setTxData(null);\n setTradeDataBuySc(null);\n setMessage(\"\");\n setError(null);\n setTxHash(null);\n }, [selectedNetwork, selectedToken]);\n\n useEffect(() => {\n const initializeTransaction = async () => {\n if (!selectedNetwork || !selectedToken) return;\n\n try {\n const networkConfig = networkSelector.getSelectedNetworkConfig();\n const receivingAddress = networkSelector.getReceivingAddress();\n const tokenAmount = networkSelector.getTokenAmount(selectedToken.key);\n\n const newTransaction = new Transaction(\n networkConfig.uri,\n networkConfig.djedAddress\n );\n await newTransaction.init();\n setTransaction(newTransaction);\n\n let tradeData = null;\n if (selectedToken.key === \"native\") {\n try {\n tradeData = await newTransaction.handleTradeDataBuySc(String(tokenAmount));\n setTradeDataBuySc(tradeData);\n } catch (tradeError) {\n console.error(\"Error fetching trade data:\", tradeError);\n }\n }\n\n setTransactionDetails({\n network: selectedNetwork,\n token: selectedToken.key,\n tokenSymbol: selectedToken.symbol,\n amount: tokenAmount || \"0\",\n receivingAddress,\n djedContractAddress: networkConfig.djedAddress,\n isDirectTransfer: selectedToken.isDirectTransfer || false,\n isNativeToken: selectedToken.isNative || false,\n tradeAmount: tradeData ? tradeData.amount : null,\n ...newTransaction.getBlockchainDetails(),\n });\n } catch (err) {\n console.error(\"Error initializing transaction:\", err);\n }\n };\n\n initializeTransaction();\n }, [selectedNetwork, selectedToken, networkSelector, setTransactionDetails]);\n\n if (!contextTransactionDetails) {\n return
Initializing transaction...
;\n }\n\n const handleConnectWallet = async () => {\n await connectWallet();\n };\n\n const handleSendTransaction = async () => {\n if (!account || !contextTransactionDetails || !transaction) {\n setMessage(\"❌ Wallet not connected or transaction details missing\");\n return;\n }\n\n try {\n setTxData(null);\n setError(null);\n setMessage(\"⏳ Preparing transaction...\");\n\n const receiver = contextTransactionDetails.receivingAddress;\n let builtTx;\n\n if (selectedToken.key === \"native\") {\n const UI = \"0x0232556C83791b8291E9b23BfEa7d67405Bd9839\";\n const amountToSend = tradeDataBuySc || \"0\";\n const valueInWei = parseEther(String(amountToSend));\n\n builtTx = await transaction.buyStablecoins(\n account,\n receiver,\n valueInWei,\n UI\n );\n\n builtTx = {\n ...builtTx,\n value: valueInWei,\n account: account,\n };\n } else {\n const networkConfig = networkSelector.getSelectedNetworkConfig();\n const stablecoinAddress = networkConfig?.tokens?.stablecoin?.address;\n \n if (!stablecoinAddress) {\n throw new Error('Stablecoin address not found in network configuration');\n }\n\n const amountToSend = contextTransactionDetails.amount\n ? parseUnits(\n String(contextTransactionDetails.amount),\n contextTransactionDetails.stableCoinDecimals\n )\n : \"0\";\n\n builtTx = {\n to: stablecoinAddress,\n value: 0n,\n data: encodeFunctionData({\n abi: [\n {\n inputs: [\n { internalType: \"address\", name: \"to\", type: \"address\" },\n { internalType: \"uint256\", name: \"amount\", type: \"uint256\" },\n ],\n name: \"transfer\",\n outputs: [{ internalType: \"bool\", name: \"\", type: \"bool\" }],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n ],\n functionName: \"transfer\",\n args: [receiver, amountToSend],\n }),\n account: account,\n };\n }\n\n setTxData(builtTx);\n setMessage(\"✅ Transaction ready! Click 'Send Transaction' to proceed.\");\n } catch (error) {\n setError(error);\n setMessage(`❌ Transaction preparation failed.`);\n }\n };\n\n const handleBuySc = async () => {\n setError(null);\n \n try {\n if (!account || !txData) {\n setMessage(\"❌ Wallet account or transaction data is missing\");\n return;\n }\n\n if (!selectedNetwork) {\n setMessage(\"❌ Network not selected\");\n return;\n }\n\n const networkConfig = networkSelector.getSelectedNetworkConfig();\n if (!networkConfig) {\n setMessage(\"❌ Network configuration not found\");\n return;\n }\n\n setMessage(\"⏳ Verifying network...\");\n\n const freshWalletClient = await ensureCorrectNetwork();\n if (!freshWalletClient) {\n setMessage(\"❌ Failed to switch to correct network. Please approve the network switch in MetaMask and try again.\");\n return;\n }\n\n if (!window.ethereum) {\n setMessage(\"❌ MetaMask not available\");\n return;\n }\n\n const chainIdHex = await window.ethereum.request({ method: 'eth_chainId' });\n const currentChainId = parseInt(chainIdHex, 16);\n\n if (currentChainId !== networkConfig.chainId) {\n const errorMsg = `Network mismatch. MetaMask is on chain ${currentChainId}, but ${selectedNetwork} requires chain ${networkConfig.chainId}. Please switch networks in MetaMask.`;\n setMessage(`❌ ${errorMsg}`);\n setError(new Error(errorMsg));\n return;\n }\n\n if (freshWalletClient.chain.id !== networkConfig.chainId) {\n const errorMsg = `Wallet client chain mismatch. Wallet client is on chain ${freshWalletClient.chain.id}, but expected ${networkConfig.chainId}.`;\n setMessage(`❌ ${errorMsg}`);\n setError(new Error(errorMsg));\n return;\n }\n\n setMessage(\"⏳ Sending transaction...\");\n\n const txHash = await freshWalletClient.sendTransaction({\n ...txData,\n account: account,\n });\n\n setTxHash(txHash);\n setMessage(`✅ Transaction sent!`);\n \n if (onTransactionComplete) {\n onTransactionComplete({\n txHash,\n network: selectedNetwork,\n token: selectedToken?.key,\n tokenSymbol: selectedToken?.symbol,\n amount: contextTransactionDetails?.amount,\n receivingAddress: contextTransactionDetails?.receivingAddress,\n });\n }\n } catch (error) {\n setError(error);\n setMessage(`❌ Transaction failed.`);\n console.error('Transaction error:', error);\n }\n };\n\n const getExplorerUrl = () => {\n if (!txHash || !selectedNetwork) return null;\n\n const explorerBaseUrls = {\n \"ethereum-classic\": \"https://blockscout.com/etc/mainnet/tx/\",\n \"sepolia\": \"https://sepolia.etherscan.io/tx/\",\n \"milkomeda-mainnet\": \"https://explorer-mainnet-cardano-evm.c1.milkomeda.com/tx/\",\n };\n\n return explorerBaseUrls[selectedNetwork]\n ? `${explorerBaseUrls[selectedNetwork]}${txHash}`\n : null;\n };\n\n return (\n
\n
\n Network:\n {contextTransactionDetails.network}\n
\n\n
\n You Pay:\n \n {selectedToken.key === \"stablecoin\"\n ? `${contextTransactionDetails.amount} ${contextTransactionDetails.tokenSymbol}`\n : `${tradeDataBuySc ? tradeDataBuySc : \"Calculating...\"} ${\n contextTransactionDetails.tokenSymbol\n }`}\n \n
\n\n \n\n {account && !txData && (\n \n )}\n {account && txData && (\n \n)}\n\n\n {message && (\n
\n {message}\n {error && (\n setIsErrorDetailsVisible(!isErrorDetailsVisible)}\n className={styles.detailsButton}\n >\n {isErrorDetailsVisible ? \"Hide Details\" : \"Show Details\"}\n \n )}\n
\n )}\n\n {isErrorDetailsVisible && error && (\n
\n
{error.message}
\n
\n )}\n\n \n {txHash && (\n
\n ✅ Transaction Hash:{\" \"}\n {getExplorerUrl() ? (\n \n {txHash.slice(0, 6)}...{txHash.slice(-6)}\n \n ) : (\n \n {txHash}\n \n )}\n
\n)}\n\n
\n );\n};\n\nexport default TransactionReview;\n","import React, { useState } from \"react\";\nimport PayButton from \"./PayButton\";\nimport Dialog from \"./Dialog\";\nimport NetworkDropdown from \"./NetworkDropdown\";\nimport TokenDropdown from \"./TokenDropdown\";\nimport TransactionReview from \"./TransactionReview\";\nimport { NetworkProvider, useNetwork } from \"../contexts/NetworkContext\";\nimport { WalletProvider } from \"../contexts/WalletContext\";\nimport styles from \"../styles/PricingCard.css\";\n\nconst WidgetContent = ({ onClose, buttonSize, onTransactionComplete }) => {\n const { resetSelections } = useNetwork(); \n\n const handleClose = () => {\n resetSelections(); // Reset selections when closing the widget\n onClose();\n };\n\n return (\n \n \n \n \n \n );\n};\n\nconst WidgetWithProviders = ({ onClose, buttonSize, networkSelector, onTransactionComplete }) => {\n return (\n \n \n \n \n \n );\n};\n\nexport const Widget = ({ networkSelector, buttonSize = \"medium\", onTransactionComplete, onSuccess }) => {\n const [isDialogOpen, setIsDialogOpen] = useState(false);\n\n const handleOpenDialog = () => {\n setIsDialogOpen(true);\n };\n\n const handleCloseDialog = () => {\n setIsDialogOpen(false);\n };\n\n // Support both onTransactionComplete and onSuccess for backwards compatibility\n const handleTransactionComplete = onTransactionComplete || onSuccess;\n\n return (\n
\n {!isDialogOpen && (\n \n )}\n {isDialogOpen && (\n \n )}\n
\n );\n};\n\nexport default Widget;\n","// src/index.js\nimport { NetworkSelector } from './core/NetworkSelector';\nimport { Transaction } from './core/Transaction';\nimport { Config } from './core/MerchantConfig';\nimport Widget from './widget/Widget.jsx';\nimport PayButton from './widget/PayButton.jsx';\nimport Dialog from './widget/Dialog.jsx';\nimport NetworkDropdown from './widget/NetworkDropdown.jsx';\nimport './styles/main.css';\nimport './styles/PricingCard.css';\n\nconst StablePay = {\n NetworkSelector,\n Transaction,\n Config,\n Widget,\n PayButton,\n Dialog,\n NetworkDropdown\n};\n\nexport default StablePay;","import { networksConfig } from \"../utils/config\";\n\nexport class NetworkSelector {\n constructor(merchantConfig) {\n this.merchantConfig = merchantConfig;\n this.blacklist = merchantConfig.getBlacklist();\n this.availableNetworks = this.getAvailableNetworks();\n this.selectedNetwork = null;\n }\n\n getAvailableNetworks() {\n return Object.entries(networksConfig).reduce(\n (acc, [networkKey, networkConfig]) => {\n if (!this.blacklist.includes(networkConfig.chainId)) {\n acc[networkKey] = networkConfig;\n }\n return acc;\n },\n {}\n );\n }\n\n selectNetwork(networkKey) {\n if (networkKey === null) {\n this.selectedNetwork = null;\n console.log(\"Network selection reset\");\n return true;\n }\n if (this.availableNetworks[networkKey]) {\n this.selectedNetwork = networkKey;\n console.log(`Network selected: ${networkKey}`);\n return true;\n }\n console.error(`Invalid network: ${networkKey}`);\n return false;\n }\n\n getSelectedNetworkConfig() {\n return this.selectedNetwork\n ? this.availableNetworks[this.selectedNetwork]\n : null;\n }\n\n getReceivingAddress() {\n return this.merchantConfig.getReceivingAddress();\n }\n\n getTokenAmount(token) {\n return this.merchantConfig.getTokenAmount(this.selectedNetwork, token);\n }\n}\n","import { networksConfig } from \"../utils/config\";\n\nexport class Config {\n constructor(options = {}) {\n this.receivingAddress = options.receivingAddress || \"\";\n this.blacklist = options.blacklist || [];\n this.amounts = options.Amounts || {}; // Note the capital 'A' in Amounts\n this.validateConfig();\n }\n\n validateConfig() {\n if (!this.receivingAddress) {\n throw new Error(\"Receiving address is required\");\n }\n // Validate stablecoin amounts\n for (const [network, tokens] of Object.entries(this.amounts)) {\n if (!networksConfig[network]) {\n throw new Error(`Invalid network: ${network}`);\n }\n if (\n !tokens.stablecoin ||\n typeof tokens.stablecoin !== \"number\" ||\n tokens.stablecoin <= 0\n ) {\n throw new Error(`Invalid stablecoin amount for network ${network}`);\n }\n }\n }\n\n getBlacklist() {\n return this.blacklist;\n }\n\n getReceivingAddress() {\n return this.receivingAddress;\n }\n\n // getTokenAmount(network, token) {\n // const networkConfig = networksConfig[network];\n // if (!networkConfig) return 0;\n\n // const stablecoinSymbol = networkConfig.tokens.stablecoin.symbol;\n\n // if (token === 'stablecoin') {\n // return this.amounts[network]?.stablecoin || 0;\n // }\n // // For native tokens, return 0 as it's not specified in the new structure\n // return 0;\n // }\n getTokenAmount(network) {\n console.log(\"Getting amount for network:\", network);\n console.log(\"Amounts object:\", this.amounts);\n\n // Directly return the stablecoin amount for the network\n const amount = this.amounts[network]?.stablecoin;\n console.log(\"Returning amount:\", amount);\n\n return amount || 0;\n }\n}\n\nexport default Config;\n"],"names":["networksConfig","sepolia","uri","chainId","djedAddress","tokens","stablecoin","symbol","address","decimals","isDirectTransfer","native","isNative","feeUI","Transaction","constructor","networkUri","this","init","Error","web3","getWeb3","djedContract","getDjedContract","stableCoin","reserveCoin","getCoinContracts","scDecimals","rcDecimals","getDecimals","oracleContract","getOracleAddress","then","addr","getOracleContract","_address","oracleAddress","contractError","console","error","message","includes","getNetworkInfo","name","networkName","getNetworkName","getBlockchainDetails","web3Available","djedContractAvailable","stableCoinAddress","reserveCoinAddress","stableCoinDecimals","reserveCoinDecimals","oracleContractAvailable","handleTradeDataBuySc","amountScaled","tradeDataPriceBuySc","totalBCScaled","buyStablecoins","payer","receiver","value","UI","buyScTx","PayButton","onClick","size","sizeStyles","small","width","height","fontSize","medium","large","logoSizes","buttonStyle","logoStyle","React","createElement","className","styles","style","Dialog","children","onClose","dialogOverlay","pricingCard","dialogClose","pricingCardHeader","allianceLogo","stablepayTitle","pricingCardBody","TokenSelector","networkSelector","selectedToken","selectToken","tokenKey","networkConfig","getSelectedNetworkConfig","key","getSelectedToken","getAvailableTokens","Object","entries","map","config","resetSelection","NetworkContext","createContext","NetworkProvider","tokenSelector","useState","selectedNetwork","setSelectedNetwork","setSelectedToken","transactionDetails","setTransactionDetails","resetState","useEffect","Provider","selectNetwork","networkKey","token","resetSelections","useNetwork","context","useContext","undefined","NetworkDropdown","selectField","htmlFor","id","onChange","event","target","disabled","keys","availableNetworks","TokenDropdown","loading","setLoading","setError","availableTokens","async","newValue","transaction","tokenAmount","getTokenAmount","blockchainDetails","tradeData","String","network","tokenSymbol","amount","receivingAddress","getReceivingAddress","djedContractAddress","isNativeToken","tradeAmount","err","defineChain","nativeCurrency","rpcUrls","default","http","webSocket","blockExplorers","url","testnet","milkomeda","etcMainnet","WalletContext","switchToNetwork","window","ethereum","chainConfig","toString","chainName","blockExplorerUrls","getChainConfigForWallet","request","method","params","switchError","code","addError","WalletProvider","walletClient","setWalletClient","publicClient","setPublicClient","account","setAccount","setChainId","balance","setBalance","isConnecting","setIsConnecting","selectedChain","getChainByNetworkKey","expectedChainId","handleAccountsChangedRef","useRef","handleChainChangedRef","disconnectWalletInternal","useCallback","handleChainChanged","newChainId","parseInt","chainIdHex","newWalletClient","createWalletClient","chain","transport","custom","current","handleAccountsChanged","accounts","length","accountsHandler","chainHandler","removeListener","newPublicClient","createPublicClient","getBalance","parseFloat","Math","pow","disconnectWallet","connectPublicClient","connectWallet","on","ensureCorrectNetwork","NETWORK_SWITCH_DELAY_MS","Promise","resolve","setTimeout","newChainIdHex","freshWalletClient","prevNetworkRef","TransactionReview","onTransactionComplete","contextTransactionDetails","useWallet","setTransaction","tradeDataBuySc","setTradeDataBuySc","txData","setTxData","setMessage","txHash","setTxHash","isErrorDetailsVisible","setIsErrorDetailsVisible","newTransaction","tradeError","initializeTransaction","getExplorerUrl","explorerBaseUrls","transactionReview","transactionInfo","transactionLabel","transactionValue","walletButton","builtTx","amountToSend","valueInWei","parseEther","stablecoinAddress","parseUnits","to","data","encodeFunctionData","abi","inputs","internalType","type","outputs","stateMutability","functionName","args","currentChainId","errorMsg","sendTransaction","detailsButton","errorDetails","transactionLink","href","rel","explorerLink","color","textDecoration","fontWeight","cursor","wordBreak","slice","WidgetContent","buttonSize","handleClose","WidgetWithProviders","NetworkSelector","merchantConfig","blacklist","getBlacklist","getAvailableNetworks","reduce","acc","log","Config","options","amounts","Amounts","validateConfig","Widget","onSuccess","isDialogOpen","setIsDialogOpen","handleTransactionComplete","widgetContainer","handleOpenDialog","handleCloseDialog"],"mappings":"2YACO,MAAMA,EAAiB,CAC5BC,QAAW,CACTC,IAAK,2CACLC,QAAS,SACTC,YAAa,6CACbC,OAAQ,CACNC,WAAY,CACVC,OAAQ,MACRC,QAAS,6CACTC,SAAU,GACVC,kBAAkB,GAEpBC,OAAQ,CACNJ,OAAQ,MACRE,SAAU,GACVG,UAAU,IAGdC,MAAO,GAET,oBAAqB,CACnBX,IAAK,mDACLC,QAAS,KACTC,YAAa,6CACbC,OAAQ,CACNC,WAAY,CACVC,OAAQ,MACRC,QAAS,6CACTC,SAAU,GACVC,kBAAkB,GAEpBC,OAAQ,CACNJ,OAAQ,OACRE,SAAU,GACVG,UAAU,IAGdC,MAAO,GAET,mBAAoB,CAClBX,IAAK,yBACLC,QAAS,GACTC,YAAa,6CACbC,OAAQ,CACNC,WAAY,CACVC,OAAQ,OACRC,QAAS,6CACTC,SAAU,GACVC,kBAAkB,GAEpBC,OAAQ,CACNJ,OAAQ,MACRE,SAAU,GACVG,UAAU,IAGdC,MAAO,ICvDJ,MAAMC,EACXC,WAAAA,CAAYC,EAAYZ,GACtBa,KAAKD,WAAaA,EAClBC,KAAKb,YAAcA,CACrB,CAEA,UAAMc,GACJ,IAAKD,KAAKD,aAAeC,KAAKb,YAC5B,MAAM,IAAIe,MAAM,6CAGlB,IACEF,KAAKG,WAAaC,EAAOA,QAACJ,KAAKD,YAC/BC,KAAKK,aAAeC,kBAAgBN,KAAKG,KAAMH,KAAKb,aAEpD,IACA,MAAMoB,WAAEA,EAAUC,YAAEA,SAAsBC,EAAgBA,iBAACT,KAAKK,aAAcL,KAAKG,OAC7EO,WAAEA,EAAUC,WAAEA,SAAqBC,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EAAK,EAaqB1P,KAAMuO,IAE7CkB,GACC9O,EAAAC,cAAC6N,EAAmB,CAClBvN,QAdkB4O,KACxBJ,GAAgB,EAAM,EAchBnB,WAAYA,EACZ5M,gBAAiBA,EACjBoJ,sBAAuB4E,IAGvB,EChDR7P,YACAkB,SACA8C"} \ No newline at end of file +{"version":3,"file":"index.js","sources":["../../src/utils/config.js","../../src/core/Transaction.js","../../src/widget/PayButton.jsx","../../src/widget/Dialog.jsx","../../src/core/TokenSelector.js","../../src/contexts/NetworkContext.jsx","../../src/widget/NetworkDropdown.jsx","../../src/widget/TokenDropdown.jsx","../../src/contexts/chains.js","../../src/contexts/WalletContext.jsx","../../src/widget/TransactionReview.jsx","../../src/widget/Widget.jsx","../../src/index.js","../../src/core/NetworkSelector.js","../../src/core/MerchantConfig.js"],"sourcesContent":["// src/utils/config.js\nexport const networksConfig = {\n 'sepolia': {\n uri: 'https://ethereum-sepolia.publicnode.com/',\n chainId: 11155111,\n djedAddress: '0x624FcD0a1F9B5820c950FefD48087531d38387f4',\n tokens: {\n stablecoin: {\n symbol: 'SOD',\n address: '0x6b930182787F346F18666D167e8d32166dC5eFBD',\n decimals: 18,\n isDirectTransfer: true\n },\n native: {\n symbol: 'ETH',\n decimals: 18,\n isNative: true\n }\n },\n feeUI: 0\n },\n 'milkomeda-mainnet': {\n uri: 'https://rpc-mainnet-cardano-evm.c1.milkomeda.com',\n chainId: 2001,\n djedAddress: '0x67A30B399F5Ed499C1a6Bc0358FA6e42Ea4BCe76',\n tokens: {\n stablecoin: {\n symbol: 'MOD',\n address: '0xcbA90fB1003b9D1bc6a2b66257D2585011b004e9',\n decimals: 18,\n isDirectTransfer: true\n },\n native: {\n symbol: 'mADA',\n decimals: 18,\n isNative: true\n }\n },\n feeUI: 0\n },\n 'ethereum-classic': {\n uri: 'https://etc.rivet.link',\n chainId: 61,\n djedAddress: '0xCc3664d7021FD36B1Fe2b136e2324710c8442cCf',\n tokens: {\n stablecoin: {\n symbol: 'ECSD',\n address: '0x5A7Ca94F6E969C94bef4CE5e2f90ed9d4891918A',\n decimals: 18,\n isDirectTransfer: true\n },\n native: {\n symbol: 'ETC',\n decimals: 18,\n isNative: true\n }\n },\n feeUI: 0\n }\n};","import { getWeb3, getDjedContract, getCoinContracts, getDecimals, getOracleAddress, getOracleContract, tradeDataPriceBuySc, buyScTx, checkAllowance, approveTx, buyScIsisTx } from 'djed-sdk';\nimport coinArtifact from 'djed-sdk/src/artifacts/CoinABI.json'; // Importing CoinABI from SDK\n\nexport class Transaction {\n constructor(networkUri, djedAddress, baseAssetAddress = null) {\n this.networkUri = networkUri;\n this.djedAddress = djedAddress;\n this.baseAssetAddress = baseAssetAddress; // Address of the ERC20 Base Asset (optional)\n }\n\n async init() {\n if (!this.networkUri || !this.djedAddress) {\n throw new Error('Network URI and DJED address are required');\n }\n\n try {\n this.web3 = await getWeb3(this.networkUri);\n this.djedContract = getDjedContract(this.web3, this.djedAddress);\n\n if (this.baseAssetAddress) {\n // Initialize Base Asset contract if provided\n this.baseAssetContract = new this.web3.eth.Contract(coinArtifact.abi, this.baseAssetAddress);\n }\n \n try {\n const { stableCoin, reserveCoin } = await getCoinContracts(this.djedContract, this.web3);\n const { scDecimals, rcDecimals } = await getDecimals(stableCoin, reserveCoin);\n this.stableCoin = stableCoin;\n this.reserveCoin = reserveCoin;\n this.scDecimals = scDecimals;\n this.rcDecimals = rcDecimals;\n\n this.oracleContract = await getOracleAddress(this.djedContract).then((addr) =>\n getOracleContract(this.web3, addr, this.djedContract._address)\n );\n\n this.oracleAddress = this.oracleContract._address;\n } catch (contractError) {\n console.error('[Transaction] Error fetching contract details:', contractError);\n if (contractError.message && contractError.message.includes('execution reverted')) {\n const getNetworkInfo = (uri) => {\n if (uri.includes('milkomeda')) return { name: 'Milkomeda', chainId: '2001' };\n if (uri.includes('mordor')) return { name: 'Mordor Testnet', chainId: '63' };\n if (uri.includes('sepolia')) return { name: 'Sepolia', chainId: '11155111' };\n if (uri.includes('etc.rivet.link')) return { name: 'Ethereum Classic', chainId: '61' };\n return { name: 'the selected network', chainId: 'unknown' };\n };\n const { name: networkName, chainId } = getNetworkInfo(this.networkUri);\n throw new Error(\n `Failed to interact with Djed contract at ${this.djedAddress} on ${networkName}.\\n\\n` +\n `Possible causes:\\n` +\n `- The contract address may be incorrect\\n` +\n `- The contract may not be deployed on ${networkName}\\n` +\n `- The contract may not be a valid Djed contract\\n\\n` +\n `Please verify the contract address is correct for ${networkName} (Chain ID: ${chainId}).`\n );\n }\n throw contractError;\n }\n } catch (error) {\n console.error('[Transaction] Error initializing transaction:', error);\n if (error.message && (error.message.includes('CONNECTION ERROR') || error.message.includes('ERR_NAME_NOT_RESOLVED'))) {\n const getNetworkName = (uri) => {\n if (uri.includes('milkomeda')) return 'Milkomeda';\n if (uri.includes('mordor')) return 'Mordor';\n if (uri.includes('sepolia')) return 'Sepolia';\n return 'the selected network';\n };\n const networkName = getNetworkName(this.networkUri);\n throw new Error(\n `Failed to connect to ${networkName} RPC endpoint: ${this.networkUri}\\n\\n` +\n `Possible causes:\\n` +\n `- The RPC endpoint may be temporarily unavailable\\n` +\n `- DNS resolution issue (check your internet connection)\\n` +\n `- Network firewall blocking the connection\\n\\n` +\n `Please try again in a few moments or check the network status.`\n );\n }\n throw error;\n }\n }\n\n getBlockchainDetails() {\n return {\n web3Available: !!this.web3,\n djedContractAvailable: !!this.djedContract,\n stableCoinAddress: this.stableCoin ? this.stableCoin._address : 'N/A',\n reserveCoinAddress: this.reserveCoin ? this.reserveCoin._address : 'N/A',\n stableCoinDecimals: this.scDecimals,\n reserveCoinDecimals: this.rcDecimals,\n oracleAddress: this.oracleAddress || 'N/A',\n oracleContractAvailable: !!this.oracleContract,\n };\n }\n\n async handleTradeDataBuySc(amountScaled) {\n if (!this.djedContract) {\n throw new Error(\"DJED contract is not initialized\");\n }\n if (typeof amountScaled !== 'string') {\n throw new Error(\"Amount must be a string\");\n }\n try {\n const result = await tradeDataPriceBuySc(this.djedContract, this.scDecimals, amountScaled);\n return result.totalBCScaled;\n } catch (error) {\n console.error(\"Error fetching trade data for buying stablecoins: \", error);\n throw error;\n }\n }\n\n async buyStablecoins(payer, receiver, value) {\n if (!this.djedContract) {\n throw new Error(\"DJED contract is not initialized\");\n }\n try {\n const UI = '0x0232556C83791b8291E9b23BfEa7d67405Bd9839';\n\n if (this.baseAssetAddress) {\n if (!this.baseAssetContract) {\n throw new Error(\"Base Asset contract not initialized for ERC20 flow\");\n }\n return buyScIsisTx(this.djedContract, payer, receiver, value, UI, this.djedAddress);\n } else {\n return buyScTx(this.djedContract, payer, receiver, value, UI, this.djedAddress);\n }\n } catch (error) {\n console.error(\"Error executing buyStablecoins transaction: \", error);\n throw error;\n }\n }\n\n async approveBaseAsset(payer, amount) {\n if (!this.baseAssetContract) {\n throw new Error(\"No Base Asset contract to approve\");\n }\n return approveTx(this.baseAssetContract, payer, this.djedAddress, amount);\n }\n\n async checkBaseAssetAllowance(owner) {\n if (!this.baseAssetContract) {\n return 'Inf'; \n }\n return checkAllowance(this.baseAssetContract, owner, this.djedAddress);\n }\n}\n","import React from \"react\";\nimport styles from \"../styles/main.css\";\n\nconst PayButton = ({ onClick, size = \"medium\" }) => {\n const sizeStyles = {\n small: { width: \"200px\", height: \"50px\", fontSize: \"14px\" },\n medium: { width: \"250px\", height: \"60px\", fontSize: \"16px\" },\n large: { width: \"300px\", height: \"70px\", fontSize: \"18px\" },\n };\n\n const logoSizes = {\n small: { width: \"35px\", height: \"33px\" },\n medium: { width: \"40px\", height: \"38px\" },\n large: { width: \"45px\", height: \"43px\" },\n };\n\n const buttonStyle = sizeStyles[size] || sizeStyles.medium;\n const logoStyle = logoSizes[size] || logoSizes.medium;\n\n return (\n \n
\n Pay with StablePay\n \n );\n};\n\nexport default PayButton;\n","import React from 'react';\nimport styles from '../styles/PricingCard.css';\n\n\nconst Dialog = ({ children, onClose, size = 'medium' }) => {\n return (\n
\n
\n \n
\n
\n\n

StablePay

\n
\n
\n {children}\n
\n
\n
\n );\n};\n\nexport default Dialog;","// TokenSelector.js\n\nexport class TokenSelector {\n constructor(networkSelector) {\n this.networkSelector = networkSelector;\n this.selectedToken = null;\n }\n\n selectToken(tokenKey) {\n const networkConfig = this.networkSelector.getSelectedNetworkConfig();\n if (networkConfig && networkConfig.tokens[tokenKey]) {\n this.selectedToken = {\n key: tokenKey,\n ...networkConfig.tokens[tokenKey]\n };\n return true;\n }\n return false;\n }\n\n getSelectedToken() {\n return this.selectedToken;\n }\n\n getAvailableTokens() {\n const networkConfig = this.networkSelector.getSelectedNetworkConfig();\n if (!networkConfig) return [];\n\n return Object.entries(networkConfig.tokens).map(([key, config]) => ({\n key,\n ...config\n }));\n }\n\n resetSelection() {\n this.selectedToken = null;\n }\n}","import React, { createContext, useState, useContext, useEffect } from 'react';\nimport { TokenSelector } from '../core/TokenSelector';\n\nconst NetworkContext = createContext();\n\nexport const NetworkProvider = ({ children, networkSelector }) => {\n const [tokenSelector] = useState(() => new TokenSelector(networkSelector));\n const [selectedNetwork, setSelectedNetwork] = useState(null);\n const [selectedToken, setSelectedToken] = useState(null);\n const [transactionDetails, setTransactionDetails] = useState(null);\n\n const resetState = () => {\n setSelectedToken(null);\n setTransactionDetails(null);\n };\n\n const selectNetwork = (networkKey) => {\n if (networkSelector.selectNetwork(networkKey)) {\n setSelectedNetwork(networkKey);\n resetState(); \n return true;\n }\n return false;\n };\n\n const selectToken = (tokenKey) => {\n if (tokenSelector.selectToken(tokenKey)) {\n const token = tokenSelector.getSelectedToken();\n setSelectedToken(token);\n return true;\n }\n return false;\n };\n\n const resetSelections = () => {\n networkSelector.selectNetwork(null);\n setSelectedNetwork(null);\n resetState();\n };\n\n // Synchronize context state with NetworkSelector\n useEffect(() => {\n setSelectedNetwork(networkSelector.selectedNetwork);\n }, [networkSelector.selectedNetwork]);\n\n return (\n \n {children}\n \n );\n};\n\nexport const useNetwork = () => {\n const context = useContext(NetworkContext);\n if (context === undefined) {\n throw new Error('useNetwork must be used within a NetworkProvider');\n }\n return context;\n};\n\nexport default NetworkContext;","import React from 'react';\nimport { useNetwork } from '../contexts/NetworkContext';\nimport styles from '../styles/PricingCard.css';\n\nconst NetworkDropdown = () => {\n const { networkSelector, selectedNetwork, selectNetwork } = useNetwork();\n\n const handleNetworkChange = (event) => {\n selectNetwork(event.target.value);\n };\n\n return (\n
\n \n \n
\n );\n};\n\nexport default NetworkDropdown;","import React, { useState } from \"react\";\nimport { useNetwork } from \"../contexts/NetworkContext\";\nimport { Transaction } from \"../core/Transaction\";\nimport styles from \"../styles/PricingCard.css\";\n\nconst TokenDropdown = () => {\n const {\n networkSelector,\n tokenSelector,\n selectedNetwork,\n selectedToken,\n selectToken,\n setTransactionDetails,\n } = useNetwork();\n\n const [loading, setLoading] = useState(false);\n const [error, setError] = useState(null);\n\n const handleTokenChange = async (event) => {\n const newValue = event.target.value;\n setError(null);\n setLoading(true);\n\n try {\n if (selectToken(newValue)) {\n const networkConfig = networkSelector.getSelectedNetworkConfig();\n const transaction = new Transaction(\n networkConfig.uri,\n networkConfig.djedAddress\n );\n await transaction.init();\n\n const tokenAmount = networkSelector.getTokenAmount(newValue);\n const blockchainDetails = transaction.getBlockchainDetails();\n\n let tradeData = null;\n if (newValue === \"native\") {\n tradeData = await transaction.handleTradeDataBuySc(\n String(tokenAmount)\n );\n }\n\n setTransactionDetails({\n network: selectedNetwork,\n token: newValue,\n tokenSymbol: tokenSelector.getSelectedToken().symbol,\n amount: tokenAmount,\n receivingAddress: networkSelector.getReceivingAddress(),\n djedContractAddress: networkConfig.djedAddress,\n isDirectTransfer:\n tokenSelector.getSelectedToken().isDirectTransfer || false,\n isNativeToken: tokenSelector.getSelectedToken().isNative || false,\n tradeAmount: tradeData ? tradeData.amount : null,\n ...blockchainDetails,\n });\n }\n } catch (err) {\n console.error(\"Error fetching transaction details:\", err);\n setError(\"Failed to fetch transaction details. Please try again.\");\n } finally {\n setLoading(false);\n }\n };\n\n const availableTokens = selectedNetwork\n ? tokenSelector.getAvailableTokens()\n : [];\n\n return (\n
\n \n \n \n {availableTokens.map((token) => (\n \n ))}\n \n {error &&
{error}
}\n
\n );\n};\n\nexport default TokenDropdown;\n","import { defineChain } from 'viem';\nimport { sepolia } from 'viem/chains';\n\nexport const mordor = defineChain({\n id: 63,\n name: 'Mordor Testnet',\n network: 'mordor',\n nativeCurrency: {\n decimals: 18,\n name: 'Mordor Ether',\n symbol: 'METC',\n },\n rpcUrls: {\n default: {\n http: ['https://rpc.mordor.etccooperative.org'],\n webSocket: ['wss://rpc.mordor.etccooperative.org/ws'],\n },\n },\n blockExplorers: {\n default: { name: 'BlockScout', url: 'https://blockscout.com/etc/mordor' },\n },\n testnet: true,\n});\n\nexport const milkomeda = defineChain({\n id: 2001,\n name: 'Milkomeda C1 Mainnet',\n network: 'milkomeda',\n nativeCurrency: {\n decimals: 18,\n name: 'Milkomeda ADA',\n symbol: 'mADA',\n },\n rpcUrls: {\n default: {\n http: ['https://rpc-mainnet-cardano-evm.c1.milkomeda.com'],\n },\n },\n blockExplorers: {\n default: { name: 'Milkomeda Explorer', url: 'https://explorer-mainnet-cardano-evm.c1.milkomeda.com' },\n },\n testnet: false,\n});\n\nexport const etcMainnet = defineChain({\n id: 61,\n name: 'Ethereum Classic',\n network: 'etc',\n nativeCurrency: {\n decimals: 18,\n name: 'Ethereum Classic',\n symbol: 'ETC',\n },\n rpcUrls: {\n default: {\n http: ['https://etc.rivet.link'],\n },\n },\n blockExplorers: {\n default: { name: 'Blockscout', url: 'https://blockscout.com/etc/mainnet' },\n },\n testnet: false,\n});\n\nexport const getChainByNetworkKey = (networkKey) => {\n switch (networkKey) {\n case 'sepolia':\n return sepolia;\n case 'ethereum-classic':\n return etcMainnet;\n case 'milkomeda-mainnet':\n return milkomeda;\n default:\n return null;\n }\n};\n\nexport const getChainConfigForWallet = (networkKey) => {\n switch (networkKey) {\n case 'sepolia':\n return {\n chainId: `0x${sepolia.id.toString(16)}`,\n chainName: 'Sepolia',\n nativeCurrency: {\n name: 'Ether',\n symbol: 'ETH',\n decimals: 18,\n },\n rpcUrls: sepolia.rpcUrls.default.http,\n blockExplorerUrls: sepolia.blockExplorers?.default?.url ? [sepolia.blockExplorers.default.url] : [],\n };\n case 'ethereum-classic':\n return {\n chainId: `0x${etcMainnet.id.toString(16)}`,\n chainName: 'Ethereum Classic',\n nativeCurrency: {\n name: 'Ethereum Classic',\n symbol: 'ETC',\n decimals: 18,\n },\n rpcUrls: ['https://etc.rivet.link'],\n blockExplorerUrls: ['https://blockscout.com/etc/mainnet'],\n };\n case 'milkomeda-mainnet':\n return {\n chainId: `0x${milkomeda.id.toString(16)}`,\n chainName: 'Milkomeda C1 Mainnet',\n nativeCurrency: {\n name: 'Milkomeda ADA',\n symbol: 'mADA',\n decimals: 18,\n },\n rpcUrls: ['https://rpc-mainnet-cardano-evm.c1.milkomeda.com'],\n blockExplorerUrls: ['https://explorer-mainnet-cardano-evm.c1.milkomeda.com'],\n };\n default:\n return null;\n }\n};\n","import React, { createContext, useContext, useState, useCallback, useEffect, useRef } from 'react';\nimport { createWalletClient, createPublicClient, custom, http } from 'viem';\nimport { useNetwork } from './NetworkContext';\nimport { getChainByNetworkKey, getChainConfigForWallet } from './chains';\n\nconst WalletContext = createContext(null);\n\nexport const useWallet = () => {\n const context = useContext(WalletContext);\n if (!context) {\n throw new Error('useWallet must be used within a WalletProvider');\n }\n return context;\n};\n\nconst switchToNetwork = async (networkKey) => {\n if (!window.ethereum) {\n throw new Error('MetaMask not installed');\n }\n\n const chainConfig = getChainConfigForWallet(networkKey);\n if (!chainConfig) {\n throw new Error(`Unsupported network: ${networkKey}`);\n }\n\n try {\n await window.ethereum.request({\n method: 'wallet_switchEthereumChain',\n params: [{ chainId: chainConfig.chainId }],\n });\n } catch (switchError) {\n if (switchError.code === 4902) {\n try {\n await window.ethereum.request({\n method: 'wallet_addEthereumChain',\n params: [chainConfig],\n });\n } catch (addError) {\n if (addError.code === 4001) {\n throw new Error(`User rejected adding ${chainConfig.chainName} to MetaMask. Please add it manually.`);\n }\n throw new Error(`Failed to add ${chainConfig.chainName} to MetaMask: ${addError.message}`);\n }\n } else if (switchError.code === 4001) {\n throw new Error(`User rejected switching to ${chainConfig.chainName}. Please switch manually in MetaMask.`);\n } else {\n throw new Error(`Failed to switch to ${chainConfig.chainName}: ${switchError.message}`);\n }\n }\n};\n\nexport const WalletProvider = ({ children }) => {\n const { selectedNetwork } = useNetwork();\n const [walletClient, setWalletClient] = useState(null);\n const [publicClient, setPublicClient] = useState(null);\n const [account, setAccount] = useState(null);\n const [chainId, setChainId] = useState(null);\n const [balance, setBalance] = useState(null);\n const [error, setError] = useState(null);\n const [isConnecting, setIsConnecting] = useState(false);\n\n const selectedChain = selectedNetwork ? getChainByNetworkKey(selectedNetwork) : null;\n const expectedChainId = selectedChain ? selectedChain.id : null;\n\n const handleAccountsChangedRef = useRef(null);\n const handleChainChangedRef = useRef(null);\n\n const disconnectWalletInternal = useCallback(() => {\n setWalletClient(null);\n setPublicClient(null);\n setAccount(null);\n setChainId(null);\n setBalance(null);\n setError(null);\n }, []);\n\n const handleChainChanged = useCallback(async (chainIdHex) => {\n const newChainId = parseInt(chainIdHex, 16);\n setChainId(newChainId);\n\n if (selectedChain && newChainId === expectedChainId) {\n setError(null);\n if (window.ethereum && selectedChain) {\n const newWalletClient = createWalletClient({ \n chain: selectedChain, \n transport: custom(window.ethereum) \n });\n setWalletClient(newWalletClient);\n }\n } else if (selectedChain && newChainId !== expectedChainId) {\n const chainName = selectedChain?.name || selectedNetwork || 'selected network';\n setError(`Wrong network detected. Please switch to ${chainName}`);\n }\n }, [selectedChain, expectedChainId, selectedNetwork]);\n\n handleChainChangedRef.current = handleChainChanged;\n\n const handleAccountsChanged = useCallback(async (accounts) => {\n if (accounts.length === 0) {\n disconnectWalletInternal();\n if (window.ethereum) {\n const accountsHandler = handleAccountsChangedRef.current;\n const chainHandler = handleChainChangedRef.current;\n if (accountsHandler) {\n window.ethereum.removeListener('accountsChanged', accountsHandler);\n }\n if (chainHandler) {\n window.ethereum.removeListener('chainChanged', chainHandler);\n }\n }\n } else {\n setAccount(accounts[0]);\n if (selectedChain) {\n try {\n const newPublicClient = createPublicClient({ chain: selectedChain, transport: http() });\n setPublicClient(newPublicClient);\n const balance = await newPublicClient.getBalance({ address: accounts[0] });\n setBalance(parseFloat(balance) / Math.pow(10, 18));\n } catch (error) {\n console.error('Error fetching balance:', error);\n setBalance(null);\n }\n }\n }\n }, [selectedChain, disconnectWalletInternal]);\n\n handleAccountsChangedRef.current = handleAccountsChanged;\n\n const disconnectWallet = useCallback(() => {\n disconnectWalletInternal();\n if (window.ethereum) {\n const accountsHandler = handleAccountsChangedRef.current;\n const chainHandler = handleChainChangedRef.current;\n if (accountsHandler) {\n window.ethereum.removeListener('accountsChanged', accountsHandler);\n }\n if (chainHandler) {\n window.ethereum.removeListener('chainChanged', chainHandler);\n }\n }\n }, [disconnectWalletInternal]);\n\n const connectPublicClient = useCallback(() => {\n if (selectedChain) {\n setPublicClient(createPublicClient({ chain: selectedChain, transport: http() }));\n }\n }, [selectedChain]);\n\n const connectWallet = useCallback(async () => {\n if (!window.ethereum) {\n setError('Please install MetaMask or another Web3 wallet');\n return false;\n }\n\n if (!selectedNetwork || !selectedChain) {\n setError('Please select a network first');\n return false;\n }\n\n setIsConnecting(true);\n setError(null);\n\n try {\n const accounts = await window.ethereum.request({ \n method: 'eth_requestAccounts' \n });\n\n if (accounts.length === 0) {\n throw new Error('No wallet address found. Please unlock your wallet.');\n }\n\n const chainIdHex = await window.ethereum.request({ method: 'eth_chainId' });\n const currentChainId = parseInt(chainIdHex, 16);\n\n if (currentChainId !== expectedChainId) {\n await switchToNetwork(selectedNetwork);\n }\n\n const newWalletClient = createWalletClient({\n chain: selectedChain,\n transport: custom(window.ethereum),\n });\n\n setWalletClient(newWalletClient);\n setAccount(accounts[0]);\n setChainId(expectedChainId);\n\n const newPublicClient = createPublicClient({ chain: selectedChain, transport: http() });\n setPublicClient(newPublicClient);\n try {\n const balance = await newPublicClient.getBalance({ address: accounts[0] });\n setBalance(parseFloat(balance) / Math.pow(10, 18));\n } catch (error) {\n console.error('Error fetching balance:', error);\n setBalance(null);\n }\n\n handleAccountsChangedRef.current = handleAccountsChanged;\n handleChainChangedRef.current = handleChainChanged;\n window.ethereum.on('accountsChanged', handleAccountsChanged);\n window.ethereum.on('chainChanged', handleChainChanged);\n\n return true;\n } catch (err) {\n console.error('Error connecting wallet:', err);\n setError(err.message);\n return false;\n } finally {\n setIsConnecting(false);\n }\n }, [selectedNetwork, selectedChain, expectedChainId, handleAccountsChanged, handleChainChanged]);\n\n const ensureCorrectNetwork = useCallback(async () => {\n if (!window.ethereum || !selectedNetwork || !selectedChain || !account) {\n const errorMsg = 'Wallet not connected or network not selected';\n setError(errorMsg);\n return null;\n }\n\n try {\n const chainIdHex = await window.ethereum.request({ method: 'eth_chainId' });\n const currentChainId = parseInt(chainIdHex, 16);\n\n if (currentChainId !== expectedChainId) {\n setError(null);\n await switchToNetwork(selectedNetwork);\n const NETWORK_SWITCH_DELAY_MS = 500;\n await new Promise(resolve => setTimeout(resolve, NETWORK_SWITCH_DELAY_MS));\n \n const newChainIdHex = await window.ethereum.request({ method: 'eth_chainId' });\n const newChainId = parseInt(newChainIdHex, 16);\n if (newChainId !== expectedChainId) {\n throw new Error(`Failed to switch network. MetaMask is still on chain ${newChainId}, expected ${expectedChainId}`);\n }\n }\n\n const freshWalletClient = createWalletClient({\n chain: selectedChain,\n transport: custom(window.ethereum),\n });\n\n setWalletClient(freshWalletClient);\n setChainId(expectedChainId);\n setError(null);\n return freshWalletClient;\n } catch (err) {\n setError(err.message);\n return null;\n }\n }, [selectedNetwork, selectedChain, expectedChainId, account]);\n\n const prevNetworkRef = useRef(selectedNetwork);\n\n useEffect(() => {\n if (prevNetworkRef.current !== null && \n prevNetworkRef.current !== selectedNetwork && \n account) {\n disconnectWalletInternal();\n if (window.ethereum) {\n const accountsHandler = handleAccountsChangedRef.current;\n const chainHandler = handleChainChangedRef.current;\n if (accountsHandler) {\n window.ethereum.removeListener('accountsChanged', accountsHandler);\n }\n if (chainHandler) {\n window.ethereum.removeListener('chainChanged', chainHandler);\n }\n }\n }\n prevNetworkRef.current = selectedNetwork;\n }, [selectedNetwork, account, disconnectWalletInternal]);\n\n useEffect(() => {\n connectPublicClient();\n }, [connectPublicClient]);\n\n return (\n \n {children}\n \n );\n};","import React, { useState, useEffect } from \"react\";\nimport { useNetwork } from \"../contexts/NetworkContext\";\nimport { useWallet } from \"../contexts/WalletContext\";\nimport { Transaction } from \"../core/Transaction\";\nimport { parseEther, encodeFunctionData, parseUnits } from \"viem\"; \nimport styles from \"../styles/PricingCard.css\"; \n\nconst TransactionReview = ({ onTransactionComplete }) => {\n const {\n networkSelector,\n selectedNetwork,\n selectedToken,\n transactionDetails: contextTransactionDetails,\n setTransactionDetails,\n } = useNetwork();\n\n const {\n connectWallet,\n account,\n walletClient,\n publicClient,\n isConnecting,\n ensureCorrectNetwork,\n expectedChainId,\n } = useWallet();\n\n const [transaction, setTransaction] = useState(null);\n const [tradeDataBuySc, setTradeDataBuySc] = useState(null);\n const [txData, setTxData] = useState(null);\n const [message, setMessage] = useState(\"\");\n const [txHash, setTxHash] = useState(null);\n const [error, setError] = useState(null);\n const [isErrorDetailsVisible, setIsErrorDetailsVisible] = useState(false);\n\n useEffect(() => {\n setTxData(null);\n setTradeDataBuySc(null);\n setMessage(\"\");\n setError(null);\n setTxHash(null);\n }, [selectedNetwork, selectedToken]);\n\n useEffect(() => {\n const initializeTransaction = async () => {\n if (!selectedNetwork || !selectedToken) return;\n\n try {\n const networkConfig = networkSelector.getSelectedNetworkConfig();\n const receivingAddress = networkSelector.getReceivingAddress();\n const tokenAmount = networkSelector.getTokenAmount(selectedToken.key);\n\n const newTransaction = new Transaction(\n networkConfig.uri,\n networkConfig.djedAddress\n );\n await newTransaction.init();\n setTransaction(newTransaction);\n\n let tradeData = null;\n if (selectedToken.key === \"native\") {\n try {\n tradeData = await newTransaction.handleTradeDataBuySc(String(tokenAmount));\n setTradeDataBuySc(tradeData);\n } catch (tradeError) {\n console.error(\"Error fetching trade data:\", tradeError);\n }\n }\n\n setTransactionDetails({\n network: selectedNetwork,\n token: selectedToken.key,\n tokenSymbol: selectedToken.symbol,\n amount: tokenAmount || \"0\",\n receivingAddress,\n djedContractAddress: networkConfig.djedAddress,\n isDirectTransfer: selectedToken.isDirectTransfer || false,\n isNativeToken: selectedToken.isNative || false,\n tradeAmount: tradeData ? tradeData.amount : null,\n ...newTransaction.getBlockchainDetails(),\n });\n } catch (err) {\n console.error(\"Error initializing transaction:\", err);\n }\n };\n\n initializeTransaction();\n }, [selectedNetwork, selectedToken, networkSelector, setTransactionDetails]);\n\n if (!contextTransactionDetails) {\n return
Initializing transaction...
;\n }\n\n const handleConnectWallet = async () => {\n await connectWallet();\n };\n\n const handleSendTransaction = async () => {\n if (!account || !contextTransactionDetails || !transaction) {\n setMessage(\"❌ Wallet not connected or transaction details missing\");\n return;\n }\n\n try {\n setTxData(null);\n setError(null);\n setMessage(\"⏳ Preparing transaction...\");\n\n const receiver = contextTransactionDetails.receivingAddress;\n let builtTx;\n\n if (selectedToken.key === \"native\") {\n const UI = \"0x0232556C83791b8291E9b23BfEa7d67405Bd9839\";\n const amountToSend = tradeDataBuySc || \"0\";\n const valueInWei = parseEther(String(amountToSend));\n\n builtTx = await transaction.buyStablecoins(\n account,\n receiver,\n valueInWei,\n UI\n );\n\n builtTx = {\n ...builtTx,\n value: valueInWei,\n account: account,\n };\n } else {\n const networkConfig = networkSelector.getSelectedNetworkConfig();\n const stablecoinAddress = networkConfig?.tokens?.stablecoin?.address;\n \n if (!stablecoinAddress) {\n throw new Error('Stablecoin address not found in network configuration');\n }\n\n const amountToSend = contextTransactionDetails.amount\n ? parseUnits(\n String(contextTransactionDetails.amount),\n contextTransactionDetails.stableCoinDecimals\n )\n : \"0\";\n\n builtTx = {\n to: stablecoinAddress,\n value: 0n,\n data: encodeFunctionData({\n abi: [\n {\n inputs: [\n { internalType: \"address\", name: \"to\", type: \"address\" },\n { internalType: \"uint256\", name: \"amount\", type: \"uint256\" },\n ],\n name: \"transfer\",\n outputs: [{ internalType: \"bool\", name: \"\", type: \"bool\" }],\n stateMutability: \"nonpayable\",\n type: \"function\",\n },\n ],\n functionName: \"transfer\",\n args: [receiver, amountToSend],\n }),\n account: account,\n };\n }\n\n setTxData(builtTx);\n setMessage(\"✅ Transaction ready! Click 'Send Transaction' to proceed.\");\n } catch (error) {\n setError(error);\n setMessage(`❌ Transaction preparation failed.`);\n }\n };\n\n const handleBuySc = async () => {\n setError(null);\n \n try {\n if (!account || !txData) {\n setMessage(\"❌ Wallet account or transaction data is missing\");\n return;\n }\n\n if (!selectedNetwork) {\n setMessage(\"❌ Network not selected\");\n return;\n }\n\n const networkConfig = networkSelector.getSelectedNetworkConfig();\n if (!networkConfig) {\n setMessage(\"❌ Network configuration not found\");\n return;\n }\n\n setMessage(\"⏳ Verifying network...\");\n\n const freshWalletClient = await ensureCorrectNetwork();\n if (!freshWalletClient) {\n setMessage(\"❌ Failed to switch to correct network. Please approve the network switch in MetaMask and try again.\");\n return;\n }\n\n if (!window.ethereum) {\n setMessage(\"❌ MetaMask not available\");\n return;\n }\n\n const chainIdHex = await window.ethereum.request({ method: 'eth_chainId' });\n const currentChainId = parseInt(chainIdHex, 16);\n\n if (currentChainId !== networkConfig.chainId) {\n const errorMsg = `Network mismatch. MetaMask is on chain ${currentChainId}, but ${selectedNetwork} requires chain ${networkConfig.chainId}. Please switch networks in MetaMask.`;\n setMessage(`❌ ${errorMsg}`);\n setError(new Error(errorMsg));\n return;\n }\n\n if (freshWalletClient.chain.id !== networkConfig.chainId) {\n const errorMsg = `Wallet client chain mismatch. Wallet client is on chain ${freshWalletClient.chain.id}, but expected ${networkConfig.chainId}.`;\n setMessage(`❌ ${errorMsg}`);\n setError(new Error(errorMsg));\n return;\n }\n\n setMessage(\"⏳ Sending transaction...\");\n\n const txHash = await freshWalletClient.sendTransaction({\n ...txData,\n account: account,\n });\n\n setTxHash(txHash);\n setMessage(`✅ Transaction sent!`);\n \n if (onTransactionComplete) {\n onTransactionComplete({\n txHash,\n network: selectedNetwork,\n token: selectedToken?.key,\n tokenSymbol: selectedToken?.symbol,\n amount: contextTransactionDetails?.amount,\n receivingAddress: contextTransactionDetails?.receivingAddress,\n });\n }\n } catch (error) {\n setError(error);\n setMessage(`❌ Transaction failed.`);\n console.error('Transaction error:', error);\n }\n };\n\n const getExplorerUrl = () => {\n if (!txHash || !selectedNetwork) return null;\n\n const explorerBaseUrls = {\n \"ethereum-classic\": \"https://blockscout.com/etc/mainnet/tx/\",\n \"sepolia\": \"https://sepolia.etherscan.io/tx/\",\n \"milkomeda-mainnet\": \"https://explorer-mainnet-cardano-evm.c1.milkomeda.com/tx/\",\n };\n\n return explorerBaseUrls[selectedNetwork]\n ? `${explorerBaseUrls[selectedNetwork]}${txHash}`\n : null;\n };\n\n return (\n
\n
\n Network:\n {contextTransactionDetails.network}\n
\n\n
\n You Pay:\n \n {selectedToken.key === \"stablecoin\"\n ? `${contextTransactionDetails.amount} ${contextTransactionDetails.tokenSymbol}`\n : `${tradeDataBuySc ? tradeDataBuySc : \"Calculating...\"} ${\n contextTransactionDetails.tokenSymbol\n }`}\n \n
\n\n \n\n {account && !txData && (\n \n )}\n {account && txData && (\n \n)}\n\n\n {message && (\n
\n {message}\n {error && (\n setIsErrorDetailsVisible(!isErrorDetailsVisible)}\n className={styles.detailsButton}\n >\n {isErrorDetailsVisible ? \"Hide Details\" : \"Show Details\"}\n \n )}\n
\n )}\n\n {isErrorDetailsVisible && error && (\n
\n
{error.message}
\n
\n )}\n\n \n {txHash && (\n
\n ✅ Transaction Hash:{\" \"}\n {getExplorerUrl() ? (\n \n {txHash.slice(0, 6)}...{txHash.slice(-6)}\n \n ) : (\n \n {txHash}\n \n )}\n
\n)}\n\n
\n );\n};\n\nexport default TransactionReview;\n","import React, { useState } from \"react\";\nimport PayButton from \"./PayButton\";\nimport Dialog from \"./Dialog\";\nimport NetworkDropdown from \"./NetworkDropdown\";\nimport TokenDropdown from \"./TokenDropdown\";\nimport TransactionReview from \"./TransactionReview\";\nimport { NetworkProvider, useNetwork } from \"../contexts/NetworkContext\";\nimport { WalletProvider } from \"../contexts/WalletContext\";\nimport styles from \"../styles/PricingCard.css\";\n\nconst WidgetContent = ({ onClose, buttonSize, onTransactionComplete }) => {\n const { resetSelections } = useNetwork(); \n\n const handleClose = () => {\n resetSelections(); // Reset selections when closing the widget\n onClose();\n };\n\n return (\n \n \n \n \n \n );\n};\n\nconst WidgetWithProviders = ({ onClose, buttonSize, networkSelector, onTransactionComplete }) => {\n return (\n \n \n \n \n \n );\n};\n\nexport const Widget = ({ networkSelector, buttonSize = \"medium\", onTransactionComplete, onSuccess }) => {\n const [isDialogOpen, setIsDialogOpen] = useState(false);\n\n const handleOpenDialog = () => {\n setIsDialogOpen(true);\n };\n\n const handleCloseDialog = () => {\n setIsDialogOpen(false);\n };\n\n // Support both onTransactionComplete and onSuccess for backwards compatibility\n const handleTransactionComplete = onTransactionComplete || onSuccess;\n\n return (\n
\n {!isDialogOpen && (\n \n )}\n {isDialogOpen && (\n \n )}\n
\n );\n};\n\nexport default Widget;\n","// src/index.js\nimport { NetworkSelector } from './core/NetworkSelector';\nimport { Transaction } from './core/Transaction';\nimport { Config } from './core/MerchantConfig';\nimport Widget from './widget/Widget.jsx';\nimport PayButton from './widget/PayButton.jsx';\nimport Dialog from './widget/Dialog.jsx';\nimport NetworkDropdown from './widget/NetworkDropdown.jsx';\nimport './styles/main.css';\nimport './styles/PricingCard.css';\n\nconst StablePay = {\n NetworkSelector,\n Transaction,\n Config,\n Widget,\n PayButton,\n Dialog,\n NetworkDropdown\n};\n\nexport default StablePay;","import { networksConfig } from \"../utils/config\";\n\nexport class NetworkSelector {\n constructor(merchantConfig) {\n this.merchantConfig = merchantConfig;\n this.blacklist = merchantConfig.getBlacklist();\n this.availableNetworks = this.getAvailableNetworks();\n this.selectedNetwork = null;\n }\n\n getAvailableNetworks() {\n return Object.entries(networksConfig).reduce(\n (acc, [networkKey, networkConfig]) => {\n if (!this.blacklist.includes(networkConfig.chainId)) {\n acc[networkKey] = networkConfig;\n }\n return acc;\n },\n {}\n );\n }\n\n selectNetwork(networkKey) {\n if (networkKey === null) {\n this.selectedNetwork = null;\n console.log(\"Network selection reset\");\n return true;\n }\n if (this.availableNetworks[networkKey]) {\n this.selectedNetwork = networkKey;\n console.log(`Network selected: ${networkKey}`);\n return true;\n }\n console.error(`Invalid network: ${networkKey}`);\n return false;\n }\n\n getSelectedNetworkConfig() {\n return this.selectedNetwork\n ? this.availableNetworks[this.selectedNetwork]\n : null;\n }\n\n getReceivingAddress() {\n return this.merchantConfig.getReceivingAddress();\n }\n\n getTokenAmount(token) {\n return this.merchantConfig.getTokenAmount(this.selectedNetwork, token);\n }\n}\n","import { networksConfig } from \"../utils/config\";\n\nexport class Config {\n constructor(options = {}) {\n this.receivingAddress = options.receivingAddress || \"\";\n this.blacklist = options.blacklist || [];\n this.amounts = options.Amounts || {}; // Note the capital 'A' in Amounts\n this.validateConfig();\n }\n\n validateConfig() {\n if (!this.receivingAddress) {\n throw new Error(\"Receiving address is required\");\n }\n // Validate stablecoin amounts\n for (const [network, tokens] of Object.entries(this.amounts)) {\n if (!networksConfig[network]) {\n throw new Error(`Invalid network: ${network}`);\n }\n if (\n !tokens.stablecoin ||\n typeof tokens.stablecoin !== \"number\" ||\n tokens.stablecoin <= 0\n ) {\n throw new Error(`Invalid stablecoin amount for network ${network}`);\n }\n }\n }\n\n getBlacklist() {\n return this.blacklist;\n }\n\n getReceivingAddress() {\n return this.receivingAddress;\n }\n\n // getTokenAmount(network, token) {\n // const networkConfig = networksConfig[network];\n // if (!networkConfig) return 0;\n\n // const stablecoinSymbol = networkConfig.tokens.stablecoin.symbol;\n\n // if (token === 'stablecoin') {\n // return this.amounts[network]?.stablecoin || 0;\n // }\n // // For native tokens, return 0 as it's not specified in the new structure\n // return 0;\n // }\n getTokenAmount(network) {\n console.log(\"Getting amount for network:\", network);\n console.log(\"Amounts object:\", this.amounts);\n\n // Directly return the stablecoin amount for the network\n const amount = this.amounts[network]?.stablecoin;\n console.log(\"Returning amount:\", amount);\n\n return amount || 0;\n }\n}\n\nexport default Config;\n"],"names":["networksConfig","sepolia","uri","chainId","djedAddress","tokens","stablecoin","symbol","address","decimals","isDirectTransfer","native","isNative","feeUI","Transaction","constructor","networkUri","baseAssetAddress","this","init","Error","web3","getWeb3","djedContract","getDjedContract","baseAssetContract","eth","Contract","coinArtifact","stableCoin","reserveCoin","getCoinContracts","scDecimals","rcDecimals","getDecimals","oracleContract","getOracleAddress","then","addr","getOracleContract","_address","oracleAddress","contractError","console","error","message","includes","getNetworkInfo","name","networkName","getNetworkName","getBlockchainDetails","web3Available","djedContractAvailable","stableCoinAddress","reserveCoinAddress","stableCoinDecimals","reserveCoinDecimals","oracleContractAvailable","handleTradeDataBuySc","amountScaled","tradeDataPriceBuySc","totalBCScaled","buyStablecoins","payer","receiver","value","UI","buyScIsisTx","buyScTx","approveBaseAsset","amount","approveTx","checkBaseAssetAllowance","owner","checkAllowance","PayButton","onClick","size","sizeStyles","small","width","height","fontSize","medium","large","logoSizes","buttonStyle","logoStyle","React","createElement","className","styles","style","Dialog","children","onClose","dialogOverlay","pricingCard","dialogClose","pricingCardHeader","allianceLogo","stablepayTitle","pricingCardBody","TokenSelector","networkSelector","selectedToken","selectToken","tokenKey","networkConfig","getSelectedNetworkConfig","key","getSelectedToken","getAvailableTokens","Object","entries","map","config","resetSelection","NetworkContext","createContext","NetworkProvider","tokenSelector","useState","selectedNetwork","setSelectedNetwork","setSelectedToken","transactionDetails","setTransactionDetails","resetState","useEffect","Provider","selectNetwork","networkKey","token","resetSelections","useNetwork","context","useContext","undefined","NetworkDropdown","selectField","htmlFor","id","onChange","event","target","disabled","keys","availableNetworks","TokenDropdown","loading","setLoading","setError","availableTokens","async","newValue","transaction","tokenAmount","getTokenAmount","blockchainDetails","tradeData","String","network","tokenSymbol","receivingAddress","getReceivingAddress","djedContractAddress","isNativeToken","tradeAmount","err","defineChain","nativeCurrency","rpcUrls","default","http","webSocket","blockExplorers","url","testnet","milkomeda","etcMainnet","WalletContext","switchToNetwork","window","ethereum","chainConfig","toString","chainName","blockExplorerUrls","getChainConfigForWallet","request","method","params","switchError","code","addError","WalletProvider","walletClient","setWalletClient","publicClient","setPublicClient","account","setAccount","setChainId","balance","setBalance","isConnecting","setIsConnecting","selectedChain","getChainByNetworkKey","expectedChainId","handleAccountsChangedRef","useRef","handleChainChangedRef","disconnectWalletInternal","useCallback","handleChainChanged","newChainId","parseInt","chainIdHex","newWalletClient","createWalletClient","chain","transport","custom","current","handleAccountsChanged","accounts","length","accountsHandler","chainHandler","removeListener","newPublicClient","createPublicClient","getBalance","parseFloat","Math","pow","disconnectWallet","connectPublicClient","connectWallet","on","ensureCorrectNetwork","NETWORK_SWITCH_DELAY_MS","Promise","resolve","setTimeout","newChainIdHex","freshWalletClient","prevNetworkRef","TransactionReview","onTransactionComplete","contextTransactionDetails","useWallet","setTransaction","tradeDataBuySc","setTradeDataBuySc","txData","setTxData","setMessage","txHash","setTxHash","isErrorDetailsVisible","setIsErrorDetailsVisible","newTransaction","tradeError","initializeTransaction","getExplorerUrl","explorerBaseUrls","transactionReview","transactionInfo","transactionLabel","transactionValue","walletButton","builtTx","amountToSend","valueInWei","parseEther","stablecoinAddress","parseUnits","to","data","encodeFunctionData","abi","inputs","internalType","type","outputs","stateMutability","functionName","args","currentChainId","errorMsg","sendTransaction","detailsButton","errorDetails","transactionLink","href","rel","explorerLink","color","textDecoration","fontWeight","cursor","wordBreak","slice","WidgetContent","buttonSize","handleClose","WidgetWithProviders","NetworkSelector","merchantConfig","blacklist","getBlacklist","getAvailableNetworks","reduce","acc","log","Config","options","amounts","Amounts","validateConfig","Widget","onSuccess","isDialogOpen","setIsDialogOpen","handleTransactionComplete","widgetContainer","handleOpenDialog","handleCloseDialog"],"mappings":"2YACO,MAAMA,EAAiB,CAC5BC,QAAW,CACTC,IAAK,2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AGtC,OAFAqC,QAAQmR,IAAI,oBAAqBvP,GAE1BA,GAAU,CACnB,GF3CA6P,ODsBoBA,EAAG3N,kBAAiB2M,aAAa,SAAUxD,wBAAuByE,gBACtF,MAAOC,EAAcC,GAAmB5M,EAAQA,UAAC,GAW3C6M,EAA4B5E,GAAyByE,EAE3D,OACE5O,EAAAC,cAAA,MAAA,CAAKC,UAAWC,EAAO6O,kBACnBH,GACA7O,EAAAC,cAACd,EAAS,CAACC,QAdQ6P,KACvBH,GAAgB,EAAK,EAaqBzP,KAAMsO,IAE7CkB,GACC7O,EAAAC,cAAC4N,EAAmB,CAClBtN,QAdkB2O,KACxBJ,GAAgB,EAAM,EAchBnB,WAAYA,EACZ3M,gBAAiBA,EACjBmJ,sBAAuB4E,IAGvB,EChDR5P,YACAkB,SACA8C"} \ No newline at end of file diff --git a/stablepay-sdk/src/core/Transaction.js b/stablepay-sdk/src/core/Transaction.js index eb72988..005d885 100644 --- a/stablepay-sdk/src/core/Transaction.js +++ b/stablepay-sdk/src/core/Transaction.js @@ -1,9 +1,11 @@ -import { getWeb3, getDjedContract, getCoinContracts, getDecimals, getOracleAddress, getOracleContract, tradeDataPriceBuySc, buyScTx } from 'djed-sdk'; +import { getWeb3, getDjedContract, getCoinContracts, getDecimals, getOracleAddress, getOracleContract, tradeDataPriceBuySc, buyScTx, checkAllowance, approveTx, buyScIsisTx } from 'djed-sdk'; +import coinArtifact from 'djed-sdk/src/artifacts/CoinABI.json'; // Importing CoinABI from SDK export class Transaction { - constructor(networkUri, djedAddress) { + constructor(networkUri, djedAddress, baseAssetAddress = null) { this.networkUri = networkUri; this.djedAddress = djedAddress; + this.baseAssetAddress = baseAssetAddress; // Address of the ERC20 Base Asset (optional) } async init() { @@ -14,6 +16,11 @@ export class Transaction { try { this.web3 = await getWeb3(this.networkUri); this.djedContract = getDjedContract(this.web3, this.djedAddress); + + if (this.baseAssetAddress) { + // Initialize Base Asset contract if provided + this.baseAssetContract = new this.web3.eth.Contract(coinArtifact.abi, this.baseAssetAddress); + } try { const { stableCoin, reserveCoin } = await getCoinContracts(this.djedContract, this.web3); @@ -109,12 +116,31 @@ export class Transaction { try { const UI = '0x0232556C83791b8291E9b23BfEa7d67405Bd9839'; - const txData = await buyScTx(this.djedContract, payer, receiver, value, UI, this.djedAddress); - - return txData; + if (this.baseAssetAddress) { + if (!this.baseAssetContract) { + throw new Error("Base Asset contract not initialized for ERC20 flow"); + } + return buyScIsisTx(this.djedContract, payer, receiver, value, UI, this.djedAddress); + } else { + return buyScTx(this.djedContract, payer, receiver, value, UI, this.djedAddress); + } } catch (error) { console.error("Error executing buyStablecoins transaction: ", error); throw error; } } + + async approveBaseAsset(payer, amount) { + if (!this.baseAssetContract) { + throw new Error("No Base Asset contract to approve"); + } + return approveTx(this.baseAssetContract, payer, this.djedAddress, amount); + } + + async checkBaseAssetAllowance(owner) { + if (!this.baseAssetContract) { + return 'Inf'; + } + return checkAllowance(this.baseAssetContract, owner, this.djedAddress); + } }