diff --git a/abi/BNPLMarketV3.json b/abi/BNPLMarketV3.json index 1e59a8a..a46b1aa 100644 --- a/abi/BNPLMarketV3.json +++ b/abi/BNPLMarketV3.json @@ -1,1319 +1 @@ -[ - { - "inputs": [ - { - "internalType": "address", - "name": "_tellerV2", - "type": "address" - }, - { - "internalType": "address", - "name": "_marketRegistry", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_marketId", - "type": "uint256" - }, - { - "internalType": "address", - "name": "_wethAddress", - "type": "address" - }, - { - "internalType": "address", - "name": "_trustedForwarder", - "type": "address" - }, - { - "internalType": "address", - "name": "_craSigner", - "type": "address" - } - ], - "stateMutability": "nonpayable", - "type": "constructor" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint256", - "name": "discreteOrderId", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "bidId", - "type": "uint256" - } - ], - "name": "AcceptedDiscreteOrder", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint256", - "name": "bidId", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "address", - "name": "borrower", - "type": "address" - }, - { - "indexed": true, - "internalType": "address", - "name": "lender", - "type": "address" - } - ], - "name": "AssetPurchaseWithLoan", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint256", - "name": "discreteOrderId", - "type": "uint256" - } - ], - "name": "CancelledDiscreteOrder", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": true, - "internalType": "uint256", - "name": "bidId", - "type": "uint256" - }, - { - "indexed": false, - "internalType": "address", - "name": "recipient", - "type": "address" - }, - { - "indexed": false, - "internalType": "address", - "name": "tokenContract", - "type": "address" - }, - { - "indexed": false, - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - } - ], - "name": "ClaimedAsset", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint256", - "name": "discreteOrderId", - "type": "uint256" - }, - { - "indexed": true, - "internalType": "address", - "name": "borrower", - "type": "address" - } - ], - "name": "CreatedDiscreteOrder", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint8", - "name": "version", - "type": "uint8" - } - ], - "name": "Initialized", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "address", - "name": "_feeRecipient", - "type": "address" - }, - { - "indexed": false, - "internalType": "bool", - "name": "allowed", - "type": "bool" - } - ], - "name": "SetAllowedFeeRecipient", - "type": "event" - }, - { - "anonymous": false, - "inputs": [ - { - "indexed": false, - "internalType": "uint16", - "name": "pct", - "type": "uint16" - } - ], - "name": "SetReferralReward", - "type": "event" - }, - { - "inputs": [], - "name": "CONTRACT_NAME", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "CONTRACT_VERSION", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "CRA_SIGNER", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "DOMAIN_SEPARATOR", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "ETH_ADDRESS", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "__assetReceiptRegister", - "outputs": [ - { - "internalType": "address", - "name": "assetContractAddress", - "type": "address" - }, - { - "internalType": "uint256", - "name": "assetTokenId", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "quantity", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "_marketRegistry", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "_tellerV2", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_discreteOrderId", - "type": "uint256" - }, - { - "components": [ - { - "internalType": "address", - "name": "considerationToken", - "type": "address" - }, - { - "internalType": "uint256", - "name": "considerationIdentifier", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "considerationAmount", - "type": "uint256" - }, - { - "internalType": "address payable", - "name": "offerer", - "type": "address" - }, - { - "internalType": "address", - "name": "zone", - "type": "address" - }, - { - "internalType": "address", - "name": "offerToken", - "type": "address" - }, - { - "internalType": "uint256", - "name": "offerIdentifier", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "offerAmount", - "type": "uint256" - }, - { - "internalType": "enum BasicOrderType", - "name": "basicOrderType", - "type": "uint8" - }, - { - "internalType": "uint256", - "name": "startTime", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "endTime", - "type": "uint256" - }, - { - "internalType": "bytes32", - "name": "zoneHash", - "type": "bytes32" - }, - { - "internalType": "uint256", - "name": "salt", - "type": "uint256" - }, - { - "internalType": "bytes32", - "name": "offererConduitKey", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "fulfillerConduitKey", - "type": "bytes32" - }, - { - "internalType": "uint256", - "name": "totalOriginalAdditionalRecipients", - "type": "uint256" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "internalType": "address payable", - "name": "recipient", - "type": "address" - } - ], - "internalType": "struct AdditionalRecipient[]", - "name": "additionalRecipients", - "type": "tuple[]" - }, - { - "internalType": "bytes", - "name": "signature", - "type": "bytes" - } - ], - "internalType": "struct BasicOrderParameters", - "name": "_basicOrderParameters", - "type": "tuple" - } - ], - "name": "acceptDiscreteOrder", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "name": "allowedFeeRecipients", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "_discreteOrderId", - "type": "uint256" - } - ], - "name": "cancelDiscreteOrder", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "bidId", - "type": "uint256" - } - ], - "name": "claimNFTFromDefaultedLoan", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "bidId", - "type": "uint256" - } - ], - "name": "claimNFTFromRepaidLoan", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "cryptopunksEscrowBuyer", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "cryptopunksMarketAddress", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "discreteOrderCount", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "discreteOrders", - "outputs": [ - { - "internalType": "address", - "name": "borrower", - "type": "address" - }, - { - "components": [ - { - "internalType": "address", - "name": "lender", - "type": "address" - }, - { - "internalType": "uint256", - "name": "totalPurchasePrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "principal", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "downPayment", - "type": "uint256" - }, - { - "internalType": "uint32", - "name": "duration", - "type": "uint32" - }, - { - "internalType": "uint32", - "name": "signatureExpiration", - "type": "uint32" - }, - { - "internalType": "uint16", - "name": "interestRate", - "type": "uint16" - }, - { - "internalType": "string", - "name": "metadataURI", - "type": "string" - }, - { - "internalType": "address", - "name": "referralAddress", - "type": "address" - } - ], - "internalType": "struct BNPLMarket.SubmitBidArgs", - "name": "submitBidArgs", - "type": "tuple" - }, - { - "internalType": "address", - "name": "assetContractAddress", - "type": "address" - }, - { - "internalType": "uint256", - "name": "assetTokenId", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "quantity", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "bidId", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "name": "escrowedTokensForLoan", - "outputs": [ - { - "internalType": "enum IBNPLMarket.TokenType", - "name": "tokenType", - "type": "uint8" - }, - { - "internalType": "address", - "name": "tokenAddress", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "internalType": "bool", - "name": "tokenClaimed", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "address", - "name": "lender", - "type": "address" - }, - { - "internalType": "uint256", - "name": "totalPurchasePrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "principal", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "downPayment", - "type": "uint256" - }, - { - "internalType": "uint32", - "name": "duration", - "type": "uint32" - }, - { - "internalType": "uint32", - "name": "signatureExpiration", - "type": "uint32" - }, - { - "internalType": "uint16", - "name": "interestRate", - "type": "uint16" - }, - { - "internalType": "string", - "name": "metadataURI", - "type": "string" - }, - { - "internalType": "address", - "name": "referralAddress", - "type": "address" - } - ], - "internalType": "struct BNPLMarket.SubmitBidArgs", - "name": "_submitBidArgs", - "type": "tuple" - }, - { - "components": [ - { - "internalType": "address", - "name": "considerationToken", - "type": "address" - }, - { - "internalType": "uint256", - "name": "considerationIdentifier", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "considerationAmount", - "type": "uint256" - }, - { - "internalType": "address payable", - "name": "offerer", - "type": "address" - }, - { - "internalType": "address", - "name": "zone", - "type": "address" - }, - { - "internalType": "address", - "name": "offerToken", - "type": "address" - }, - { - "internalType": "uint256", - "name": "offerIdentifier", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "offerAmount", - "type": "uint256" - }, - { - "internalType": "enum BasicOrderType", - "name": "basicOrderType", - "type": "uint8" - }, - { - "internalType": "uint256", - "name": "startTime", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "endTime", - "type": "uint256" - }, - { - "internalType": "bytes32", - "name": "zoneHash", - "type": "bytes32" - }, - { - "internalType": "uint256", - "name": "salt", - "type": "uint256" - }, - { - "internalType": "bytes32", - "name": "offererConduitKey", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "fulfillerConduitKey", - "type": "bytes32" - }, - { - "internalType": "uint256", - "name": "totalOriginalAdditionalRecipients", - "type": "uint256" - }, - { - "components": [ - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - }, - { - "internalType": "address payable", - "name": "recipient", - "type": "address" - } - ], - "internalType": "struct AdditionalRecipient[]", - "name": "additionalRecipients", - "type": "tuple[]" - }, - { - "internalType": "bytes", - "name": "signature", - "type": "bytes" - } - ], - "internalType": "struct BasicOrderParameters", - "name": "_basicOrderParameters", - "type": "tuple" - }, - { - "internalType": "bytes", - "name": "_signature", - "type": "bytes" - } - ], - "name": "execute", - "outputs": [], - "stateMutability": "payable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "name": "executedSignatures", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getMarketRegistry", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "getTellerV2", - "outputs": [ - { - "internalType": "contract TellerV2", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint256", - "name": "marketId", - "type": "uint256" - } - ], - "name": "getTellerV2MarketOwner", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "address", - "name": "lender", - "type": "address" - }, - { - "internalType": "uint256", - "name": "totalPurchasePrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "principal", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "downPayment", - "type": "uint256" - }, - { - "internalType": "uint32", - "name": "duration", - "type": "uint32" - }, - { - "internalType": "uint32", - "name": "signatureExpiration", - "type": "uint32" - }, - { - "internalType": "uint16", - "name": "interestRate", - "type": "uint16" - }, - { - "internalType": "string", - "name": "metadataURI", - "type": "string" - }, - { - "internalType": "address", - "name": "referralAddress", - "type": "address" - } - ], - "internalType": "struct BNPLMarket.SubmitBidArgs", - "name": "_submitBidArgs", - "type": "tuple" - }, - { - "internalType": "address", - "name": "assetContractAddress", - "type": "address" - }, - { - "internalType": "uint256", - "name": "assetTokenId", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "assetQuantity", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "totalPurchasePrice", - "type": "uint256" - }, - { - "internalType": "address", - "name": "paymentToken", - "type": "address" - } - ], - "name": "getTypeHash", - "outputs": [ - { - "internalType": "bytes32", - "name": "", - "type": "bytes32" - } - ], - "stateMutability": "pure", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_cryptopunksMarketAddress", - "type": "address" - }, - { - "internalType": "address", - "name": "_seaportEscrowBuyer", - "type": "address" - }, - { - "internalType": "address", - "name": "_cryptopunksEscrowBuyer", - "type": "address" - } - ], - "name": "initialize", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "forwarder", - "type": "address" - } - ], - "name": "isTrustedForwarder", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "marketId", - "outputs": [ - { - "internalType": "uint256", - "name": "", - "type": "uint256" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_cryptopunksMarketAddress", - "type": "address" - }, - { - "internalType": "address", - "name": "_seaportEscrowBuyer", - "type": "address" - }, - { - "internalType": "address", - "name": "_cryptopunksEscrowBuyer", - "type": "address" - } - ], - "name": "onUpgrade", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "bytes32", - "name": "domainSeparator", - "type": "bytes32" - }, - { - "internalType": "bytes32", - "name": "typeHash", - "type": "bytes32" - }, - { - "internalType": "bytes", - "name": "_signature", - "type": "bytes" - } - ], - "name": "recoverSignature", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "referralRewardPercent", - "outputs": [ - { - "internalType": "uint16", - "name": "", - "type": "uint16" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "seaportEscrowBuyer", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "_feeRecipient", - "type": "address" - }, - { - "internalType": "bool", - "name": "_allowed", - "type": "bool" - } - ], - "name": "setAllowedFeeRecipient", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "uint16", - "name": "_pct", - "type": "uint16" - } - ], - "name": "setReferralRewardPercent", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "components": [ - { - "internalType": "address", - "name": "lender", - "type": "address" - }, - { - "internalType": "uint256", - "name": "totalPurchasePrice", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "principal", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "downPayment", - "type": "uint256" - }, - { - "internalType": "uint32", - "name": "duration", - "type": "uint32" - }, - { - "internalType": "uint32", - "name": "signatureExpiration", - "type": "uint32" - }, - { - "internalType": "uint16", - "name": "interestRate", - "type": "uint16" - }, - { - "internalType": "string", - "name": "metadataURI", - "type": "string" - }, - { - "internalType": "address", - "name": "referralAddress", - "type": "address" - } - ], - "internalType": "struct BNPLMarket.SubmitBidArgs", - "name": "_submitBidArgs", - "type": "tuple" - }, - { - "internalType": "address", - "name": "_assetContractAddress", - "type": "address" - }, - { - "internalType": "uint256", - "name": "_assetTokenId", - "type": "uint256" - }, - { - "internalType": "uint256", - "name": "_quantity", - "type": "uint256" - } - ], - "name": "submitDiscreteOrder", - "outputs": [ - { - "internalType": "uint256", - "name": "discreteOrderId", - "type": "uint256" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address", - "name": "tokenAddress", - "type": "address" - }, - { - "internalType": "uint256", - "name": "tokenId", - "type": "uint256" - }, - { - "internalType": "enum IBNPLMarket.TokenType", - "name": "tokenType", - "type": "uint8" - }, - { - "internalType": "uint256", - "name": "amount", - "type": "uint256" - } - ], - "name": "transferLegacyAssetToEscrow", - "outputs": [ - { - "internalType": "bool", - "name": "", - "type": "bool" - } - ], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [ - { - "internalType": "address[]", - "name": "tokenAddresses", - "type": "address[]" - }, - { - "internalType": "uint256[]", - "name": "tokenIds", - "type": "uint256[]" - }, - { - "internalType": "enum IBNPLMarket.TokenType[]", - "name": "tokenTypes", - "type": "uint8[]" - }, - { - "internalType": "uint256[]", - "name": "amounts", - "type": "uint256[]" - } - ], - "name": "transferLegacyAssetsArrayToEscrow", - "outputs": [], - "stateMutability": "nonpayable", - "type": "function" - }, - { - "inputs": [], - "name": "upgradedToVersion", - "outputs": [ - { - "internalType": "string", - "name": "", - "type": "string" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "inputs": [], - "name": "wethAddress", - "outputs": [ - { - "internalType": "address", - "name": "", - "type": "address" - } - ], - "stateMutability": "view", - "type": "function" - }, - { - "stateMutability": "payable", - "type": "receive" - } -] \ No newline at end of file +[{"inputs":[{"internalType":"address","name":"_tellerV2","type":"address"},{"internalType":"address","name":"_marketRegistry","type":"address"},{"internalType":"address","name":"_wethAddress","type":"address"},{"internalType":"address","name":"_trustedForwarder","type":"address"},{"internalType":"address","name":"_craSigner","type":"address"}],"stateMutability":"nonpayable","type":"constructor"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"bidId","type":"uint256"},{"indexed":true,"internalType":"address","name":"borrower","type":"address"},{"indexed":true,"internalType":"address","name":"lender","type":"address"}],"name":"AssetPurchaseWithLoan","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint256","name":"bidId","type":"uint256"},{"indexed":false,"internalType":"address","name":"recipient","type":"address"},{"indexed":false,"internalType":"address","name":"tokenContract","type":"address"},{"indexed":false,"internalType":"uint256","name":"tokenId","type":"uint256"}],"name":"ClaimedAsset","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint8","name":"version","type":"uint8"}],"name":"Initialized","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"marketId","type":"uint256"},{"indexed":false,"internalType":"address","name":"_feeRecipient","type":"address"},{"indexed":false,"internalType":"bool","name":"allowed","type":"bool"}],"name":"SetAllowedFeeRecipient","type":"event"},{"anonymous":false,"inputs":[{"indexed":false,"internalType":"uint256","name":"marketId","type":"uint256"},{"indexed":false,"internalType":"uint16","name":"pct","type":"uint16"}],"name":"SetReferralReward","type":"event"},{"inputs":[],"name":"CONTRACT_NAME","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"CONTRACT_VERSION","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"CRA_SIGNER","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"DOMAIN_SEPARATOR","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"ETH_ADDRESS","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_marketRegistry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"_tellerV2","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"},{"internalType":"address","name":"","type":"address"}],"name":"allowedFeeRecipients","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"bidId","type":"uint256"}],"name":"claimNFTFromDefaultedLoan","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"bidId","type":"uint256"}],"name":"claimNFTFromRepaidLoan","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"cryptopunksEscrowBuyer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"cryptopunksMarketAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"","type":"uint256"}],"name":"escrowedTokensForLoan","outputs":[{"internalType":"enum IBNPLMarket.TokenType","name":"tokenType","type":"uint8"},{"internalType":"address","name":"tokenAddress","type":"address"},{"internalType":"uint256","name":"tokenId","type":"uint256"},{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"bool","name":"tokenClaimed","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"address","name":"lender","type":"address"},{"internalType":"uint256","name":"totalPurchasePrice","type":"uint256"},{"internalType":"uint256","name":"principal","type":"uint256"},{"internalType":"uint256","name":"downPayment","type":"uint256"},{"internalType":"uint32","name":"duration","type":"uint32"},{"internalType":"uint32","name":"signatureExpiration","type":"uint32"},{"internalType":"uint16","name":"interestRate","type":"uint16"},{"internalType":"string","name":"metadataURI","type":"string"},{"internalType":"address","name":"referralAddress","type":"address"},{"internalType":"uint256","name":"marketId","type":"uint256"}],"internalType":"struct BNPLMarket.SubmitBidArgs","name":"_submitBidArgs","type":"tuple"},{"components":[{"internalType":"address","name":"considerationToken","type":"address"},{"internalType":"uint256","name":"considerationIdentifier","type":"uint256"},{"internalType":"uint256","name":"considerationAmount","type":"uint256"},{"internalType":"address payable","name":"offerer","type":"address"},{"internalType":"address","name":"zone","type":"address"},{"internalType":"address","name":"offerToken","type":"address"},{"internalType":"uint256","name":"offerIdentifier","type":"uint256"},{"internalType":"uint256","name":"offerAmount","type":"uint256"},{"internalType":"enum BasicOrderType","name":"basicOrderType","type":"uint8"},{"internalType":"uint256","name":"startTime","type":"uint256"},{"internalType":"uint256","name":"endTime","type":"uint256"},{"internalType":"bytes32","name":"zoneHash","type":"bytes32"},{"internalType":"uint256","name":"salt","type":"uint256"},{"internalType":"bytes32","name":"offererConduitKey","type":"bytes32"},{"internalType":"bytes32","name":"fulfillerConduitKey","type":"bytes32"},{"internalType":"uint256","name":"totalOriginalAdditionalRecipients","type":"uint256"},{"components":[{"internalType":"uint256","name":"amount","type":"uint256"},{"internalType":"address payable","name":"recipient","type":"address"}],"internalType":"struct AdditionalRecipient[]","name":"additionalRecipients","type":"tuple[]"},{"internalType":"bytes","name":"signature","type":"bytes"}],"internalType":"struct BasicOrderParameters","name":"_basicOrderParameters","type":"tuple"},{"internalType":"bytes","name":"_signatureFromBorrower","type":"bytes"},{"internalType":"bytes","name":"_signatureFromLender","type":"bytes"}],"name":"executeUsingOffchainSignatures","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"name":"executedSignatures","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getMarketRegistry","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"getTellerV2","outputs":[{"internalType":"contract TellerV2","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"marketId","type":"uint256"}],"name":"getTellerV2MarketOwner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"components":[{"internalType":"address","name":"borrower","type":"address"},{"internalType":"address","name":"lender","type":"address"},{"internalType":"uint256","name":"totalPurchasePrice","type":"uint256"},{"internalType":"uint256","name":"principal","type":"uint256"},{"internalType":"uint256","name":"downPayment","type":"uint256"},{"internalType":"uint32","name":"duration","type":"uint32"},{"internalType":"uint32","name":"signatureExpiration","type":"uint32"},{"internalType":"uint16","name":"interestRate","type":"uint16"},{"internalType":"string","name":"metadataURI","type":"string"},{"internalType":"address","name":"referralAddress","type":"address"},{"internalType":"uint256","name":"marketId","type":"uint256"}],"internalType":"struct BNPLMarket.SubmitBidArgs","name":"_submitBidArgs","type":"tuple"},{"internalType":"address","name":"assetContractAddress","type":"address"},{"internalType":"uint256","name":"assetTokenId","type":"uint256"},{"internalType":"uint256","name":"assetQuantity","type":"uint256"},{"internalType":"uint256","name":"totalPurchasePrice","type":"uint256"},{"internalType":"address","name":"paymentToken","type":"address"}],"name":"getTypeHash","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"pure","type":"function"},{"inputs":[{"internalType":"address","name":"_cryptopunksMarketAddress","type":"address"},{"internalType":"address","name":"_seaportEscrowBuyer","type":"address"},{"internalType":"address","name":"_cryptopunksEscrowBuyer","type":"address"}],"name":"initialize","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"forwarder","type":"address"}],"name":"isTrustedForwarder","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"onUpgrade","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"seaportEscrowBuyer","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"_marketId","type":"uint256"},{"internalType":"address","name":"_feeRecipient","type":"address"},{"internalType":"bool","name":"_allowed","type":"bool"}],"name":"setAllowedFeeRecipient","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"_marketId","type":"uint256"},{"internalType":"uint16","name":"_pct","type":"uint16"}],"name":"setReferralRewardPercent","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"upgradedToVersion","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"wethAddress","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"stateMutability":"payable","type":"receive"}] \ No newline at end of file diff --git a/data/contractsConfig.json b/data/contractsConfig.json index 29514fa..c292622 100644 --- a/data/contractsConfig.json +++ b/data/contractsConfig.json @@ -40,6 +40,7 @@ "BNPLContract":{ "address": "0x260C32eB38D1403bd51B83B5b7047812C70B7845" }, + "seaport":{ "address": "0x00000000006c3852cbef3e08e8df289169ede581" }, diff --git a/lib/bnpl-helper.ts b/lib/bnpl-helper.ts index eb14209..4afb3c8 100644 --- a/lib/bnpl-helper.ts +++ b/lib/bnpl-helper.ts @@ -2,15 +2,15 @@ import { parseFeeMethod, parseHowToCall, parseMetadata, parseSaleKind, WyvernAto import {BigNumber, Contract, ethers,Signer,Wallet} from 'ethers' - -import moment from 'moment' - + + import { NULL_BLOCK_HASH } from 'opensea-js/lib/constants' import { OpenseaHelper, SignedOrder, UnhashedOrder } from '../lib/opensea-helper' -import { SubmitBidArgs, ContractsConfig, CraResponse, ExecuteParams, BasicOrderParams } from "./types" +import { SubmitBidArgs, ContractsConfig, CraResponse, ExecuteParams, BasicOrderParams, DomainData } from "./types" import { axiosPostRequest } from "./axios-helper" import { craSign } from "./cra-signer" +import { ISignOfferSignerConfig, signOffchainOffer } from "@clarity-credit/anpl-sdk" require('dotenv').config() @@ -71,29 +71,29 @@ export function buildExecuteParams(inputData:CraResponse ): ExecuteParams { } + + export async function generateBNPLOrderSignature( submitBidArgs:SubmitBidArgs, basicOrderParams:BasicOrderParams, + domainData: DomainData, wallet: Wallet, - chainId: number, - implementationContractAddress: string ){ - let signatureVersion = 3 - - let signatureResponse = await craSign( - submitBidArgs, - basicOrderParams, - chainId, - signatureVersion, - implementationContractAddress, - wallet, - true) + const signConfig :ISignOfferSignerConfig = { + submitBidArgs, + basicOrderParams, + domainData, + //@ts-ignore + signer:wallet, + + } - if(signatureResponse.success){ - return signatureResponse.data - } + - return undefined + const signature = await signOffchainOffer(signConfig) + + return signature + } \ No newline at end of file diff --git a/lib/reservoir-helper.ts b/lib/reservoir-helper.ts new file mode 100644 index 0000000..a608113 --- /dev/null +++ b/lib/reservoir-helper.ts @@ -0,0 +1,225 @@ + +import axios from 'axios' +import { BigNumber } from 'ethers' +import { AdditionalRecipient, BasicOrderParams, BasicOrderParamsResponse, ReservoirOrder, SeaportProtocolData, SeaportProtocolParameters } from './types' + +require('dotenv').config() + +const RESERVOIR_API_KEY = process.env.RESERVOIR_API_KEY! + +const BLANK_SIGNATURE = + '0x0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000' + + +export async function fetchReservoirOrderById( + {orderId}:{orderId:string} + ) : Promise { + + + const apiUrl = new URL('https://api.reservoir.tools/orders/asks/v4') + + apiUrl.searchParams.set('ids', `${orderId}`) + apiUrl.searchParams.set('includeRawData', 'true') + + const headers = { + 'x-api-key': RESERVOIR_API_KEY, + 'accept':'*/*', + + } + + console.log(apiUrl.toString()) + const response = await axios.get(apiUrl.toString(), { headers }) + + + const orders = response.data.orders + + if(!orders || orders.length == 0) return undefined + + return orders[0] + +} + + + +export function formatReservoirOrder(order: ReservoirOrder): { + order: ReservoirOrder + basicOrderParams?: BasicOrderParamsResponse + } { + + + if(!order.rawData.consideration){ + console.error("No consideration within raw data") + return {order} + } + + const protocolData: SeaportProtocolData = { + parameters: { + consideration: order.rawData.consideration, + offerer: order.rawData.offerer, + zone: order.rawData.zone, + offer: order.rawData.offer, + startTime: order.rawData.startTime, + endTime: order.rawData.endTime, + orderType: order.rawData.orderType, + zoneHash: order.rawData.zoneHash, + salt: order.rawData.salt, + totalOriginalConsiderationItems: + order.rawData.consideration.length.toString(), + conduitKey: order.rawData.conduitKey, + + parameterOrderType: order.rawData.orderType, //is this correct ? probably. + }, + signature: order.rawData.signature, + } + + const generatedOrderParams: BasicOrderParams = + generateBasicOrderParamsFromSeaport(protocolData) + + return { + order: order, + basicOrderParams: formatBasicOrderParams(generatedOrderParams), + } + } + + +export function generateBasicOrderParamsFromSeaport( + orderData: SeaportProtocolData + ): BasicOrderParams { + const orderParameters: SeaportProtocolParameters = orderData.parameters + + const basicOrderParams: BasicOrderParams = { + considerationToken: orderParameters.consideration[0].token, //payment token + considerationIdentifier: BigNumber.from( + orderParameters.consideration[0].identifierOrCriteria + ), // not sure what significance this has + considerationAmount: BigNumber.from( + orderParameters.consideration[0].endAmount + ), // using the first element in the consideration array as per Andy's suggestion + offerer: orderParameters.offerer, + zone: orderParameters.zone, + offerToken: orderParameters.offer[0].token, //nft_contract + offerIdentifier: BigNumber.from( + orderParameters.offer[0].identifierOrCriteria + ), //token id + offerAmount: orderParameters.offer[0].endAmount, //quantity + basicOrderType: getBasicOrderType( + orderParameters.orderType, + orderParameters.consideration[0].itemType, + orderParameters.offer[0].itemType + ), + + startTime: BigNumber.from(orderParameters.startTime), + endTime: BigNumber.from(orderParameters.endTime), + zoneHash: orderParameters.zoneHash, + salt: BigNumber.from(orderParameters.salt).toHexString(), + offererConduitKey: orderParameters.conduitKey, + fulfillerConduitKey: + '0x0000000000000000000000000000000000000000000000000000000000000000', + totalOriginalAdditionalRecipients: BigNumber.from( + orderParameters.totalOriginalConsiderationItems + ).sub(1), + additionalRecipients: getAdditionalRecipients(orderParameters), + signature: orderData.signature ? orderData.signature : BLANK_SIGNATURE, + } + return basicOrderParams + } + + + +function getAdditionalRecipients(parameters: SeaportProtocolParameters): any[] { + const recipientsArray: object[] = [] + + for (let i = 1; i < parameters.consideration.length; i++) { + const additionalRecipient = { + amount: BigNumber.from(parameters.consideration[i].endAmount), + recipient: parameters.consideration[i].recipient, + } + + recipientsArray.push(additionalRecipient) + } + return recipientsArray + } + + +export function formatBasicOrderParams( + basicOrderParams: any + ): BasicOrderParamsResponse { + return { + considerationToken: basicOrderParams.considerationToken, + considerationIdentifier: BigNumber.from( + basicOrderParams.considerationIdentifier + ).toString(), + considerationAmount: BigNumber.from( + basicOrderParams.considerationAmount + ).toString(), + offerer: basicOrderParams.offerer, + zone: basicOrderParams.zone, + offerToken: basicOrderParams.offerToken, + offerIdentifier: BigNumber.from( + basicOrderParams.offerIdentifier + ).toString(), + offerAmount: BigNumber.from(basicOrderParams.offerAmount).toString(), + basicOrderType: basicOrderParams.basicOrderType, + startTime: BigNumber.from(basicOrderParams.startTime).toString(), + endTime: BigNumber.from(basicOrderParams.endTime).toString(), + zoneHash: basicOrderParams.zoneHash, + salt: basicOrderParams.salt, + offererConduitKey: basicOrderParams.offererConduitKey, + fulfillerConduitKey: basicOrderParams.fulfillerConduitKey, + totalOriginalAdditionalRecipients: BigNumber.from( + basicOrderParams.totalOriginalAdditionalRecipients + ).toString(), + additionalRecipients: basicOrderParams.additionalRecipients.map( + (r: AdditionalRecipient) => { + return { + amount: BigNumber.from(r.amount).toString(), + recipient: r.recipient, + } + } + ), + signature: basicOrderParams.signature, + } + } + + +function getBasicOrderType( + orderType: number, + considerationItemType: number, + offerItemType: number + ): number { + let basicOrderRouteType = 10 + //refer to the above enums to understand if else statements + if (considerationItemType == 0 && offerItemType == 2) { + basicOrderRouteType = 0 + } else if ( + considerationItemType == 0 && + (offerItemType == 3 || offerItemType == 5) + ) { + basicOrderRouteType = 1 + } else if ( + considerationItemType == 1 && + (offerItemType == 2 || offerItemType == 4) + ) { + basicOrderRouteType = 2 + } else if ( + considerationItemType == 1 && + (offerItemType == 3 || offerItemType == 5) + ) { + basicOrderRouteType = 3 + } else if ( + (considerationItemType == 2 || considerationItemType == 4) && + offerItemType == 1 + ) { + basicOrderRouteType = 4 + } else if ( + (considerationItemType == 3 || considerationItemType == 5) && + offerItemType == 1 + ) { + basicOrderRouteType = 5 + } + + +const basicOrderType = orderType + 4 * basicOrderRouteType + +return basicOrderType +} \ No newline at end of file diff --git a/lib/teller-v2-lending-helper.ts b/lib/teller-v2-lending-helper.ts new file mode 100644 index 0000000..d074e51 --- /dev/null +++ b/lib/teller-v2-lending-helper.ts @@ -0,0 +1,45 @@ +import { BigNumber } from 'ethers' + +const FACTOR = 10_000 + +/* +For ANPL, marketFeePct is 500 (5%) and protocolFeePct is 5 (0.05%) + +*/ + +export function calculatePrincipalRequiredForBorrowerPayout( + expectedBorrowerPayment: BigNumber, //5000 ///amount of wei THE BORROWER must get out of this loan + marketFeePct: BigNumber, //500 + protocolFeePct: BigNumber //5 +): BigNumber { + const totalFeesPct = marketFeePct.add(protocolFeePct) + + const principalRequired = expectedBorrowerPayment + .mul(BigNumber.from(FACTOR)) + .div(BigNumber.from(FACTOR).sub(totalFeesPct)) //rounding UP + + // ---- If we are off by 1, subtract 1 + const calculatedBorrowerPayment = calculateBorrowerPayoutFromLoanPrincipal( + principalRequired, + marketFeePct, + protocolFeePct + ) + const offByError = calculatedBorrowerPayment.sub(expectedBorrowerPayment) + + return principalRequired.sub(offByError) +} + +//this is how it happens in solidity +export function calculateBorrowerPayoutFromLoanPrincipal( + loanPrincipal: BigNumber, + marketFeePct: BigNumber, + protocolFeePct: BigNumber +): BigNumber { + const marketFee = loanPrincipal.mul(marketFeePct).div(FACTOR) + + const protocolFee = loanPrincipal.mul(protocolFeePct).div(FACTOR) + + const borrowerPayout = loanPrincipal.sub(marketFee).sub(protocolFee) + + return borrowerPayout +} diff --git a/lib/types.ts b/lib/types.ts index e23c081..ca01e1e 100644 --- a/lib/types.ts +++ b/lib/types.ts @@ -1,6 +1,84 @@ import { BigNumber } from "ethers"; + + +export interface ReservoirOrderRawData { + kind: string + salt: string + zone: string + offer: Consideration[] + counter: string + endTime: string + offerer: string + zoneHash: string + orderType: number + signature: string + startTime: string + conduitKey: string + consideration: Consideration[] +} +export interface ReservoirOrder { + id: string + kind: string + status: string + contract: string + rawData: ReservoirOrderRawData +} + + + +export interface BasicOrderParamsResponse { + considerationToken: string + considerationIdentifier: string //bn + considerationAmount: string //bn + offerer: string + zone: string + offerToken: string + offerIdentifier: string //bn + offerAmount: string + basicOrderType: number + startTime: string //bn + endTime: string //bn + zoneHash: string + salt: string + offererConduitKey: string + fulfillerConduitKey: string + totalOriginalAdditionalRecipients: string //bn + additionalRecipients: AdditionalRecipientResponse[] + signature: string +} +export interface AdditionalRecipientResponse { + amount: string //bn + recipient: string +} + +export interface SeaportProtocolData { + // was opensearesponse + // nftPrice: string; + parameters: SeaportProtocolParameters + signature: string +} + + +export interface SeaportProtocolParameters { + // was opensearesponseparameters + // nftPrice: string; + consideration: Consideration[] + parameterOrderType: number + offerer: string + zone: string + offer: Consideration[] + startTime: string + endTime: string + orderType: number + zoneHash: string + salt: string + totalOriginalConsiderationItems?: string + conduitKey: string +} + + export interface DomainData { name: string version: string @@ -20,6 +98,7 @@ export interface SubmitBidArgs { interestRate: string referralAddress: string metadataURI: string + marketId: string } @@ -74,7 +153,7 @@ export interface Consideration { startAmount: string, endAmount: string, itemType: number - + recipient?: string } /* @@ -118,11 +197,17 @@ export interface TellerInputs { offererConduitKey: string, fulfillerConduitKey: string, totalOriginalAdditionalRecipients: BigNumber, - additionalRecipients:object[], + additionalRecipients: AdditionalRecipient[], signature: string } + export interface AdditionalRecipient { + amount: BigNumber //bn + recipient: string +} + + export interface ExecuteParams { submitBidArgs: SubmitBidArgs, diff --git a/package.json b/package.json index df82d69..69aa0c6 100644 --- a/package.json +++ b/package.json @@ -12,11 +12,11 @@ "author": "", "license": "MIT", "dependencies": { + "@clarity-credit/anpl-sdk": "^0.3.5", "@types/node-fetch": "^2.6.1", "alchemy-sdk": "^2.0.5-rc1", - "@clarity-credit/anpl-sdk": "^0.1.3", "argv": "^0.0.2", - "axios": "^1.2.0", + "axios": "^1.2.3", "dotenv": "^16.0.1", "moment": "^2.29.3", "opensea-js": "^3.0.4", diff --git a/tasks/callExecute.ts b/tasks/callExecute.ts index 05dcede..bd4b69f 100644 --- a/tasks/callExecute.ts +++ b/tasks/callExecute.ts @@ -138,6 +138,7 @@ export async function callExecute(): Promise { interestRate:submitBidArgs.interestRate, referralAddress: submitBidArgs.referralAddress, metadataURI: submitBidArgs.metadataURI , + marketId: "2" } diff --git a/tasks/callExecuteWithOffchain.ts b/tasks/callExecuteWithOffchain.ts index 0f744a2..8125317 100644 --- a/tasks/callExecuteWithOffchain.ts +++ b/tasks/callExecuteWithOffchain.ts @@ -6,7 +6,7 @@ import { getRpcUrlFromNetworkName, networkNameFromChainId } from '../lib/app-hel import { buildExecuteParams, calculateTotalPrice, generateBNPLOrderSignature, performCraRequest, readSignatureVersionFromBNPLMarketContract } from '../lib/bnpl-helper' -import { BasicOrderParams, SubmitBidArgs } from '../lib/types' +import { BasicOrderParams, DomainData, SubmitBidArgs } from '../lib/types' require('dotenv').config() @@ -130,22 +130,27 @@ export async function callExecuteWithOffchain(): Promise { - + const domainData:DomainData= { + name: '', + version: '', + chainId: 0, + verifyingContract: '' + } let lenderSignature = await generateBNPLOrderSignature( submitBidArgs, - basicOrderParams, + basicOrderParams, + domainData , lenderWallet, - chainId, - implementationContractAddress + ) let borrowerSignature = await generateBNPLOrderSignature( submitBidArgs, basicOrderParams, + domainData , borrowerWallet, - chainId, - implementationContractAddress + ) @@ -183,6 +188,7 @@ export async function callExecuteWithOffchain(): Promise { interestRate:submitBidArgs.interestRate, referralAddress: submitBidArgs.referralAddress, metadataURI: submitBidArgs.metadataURI , + marketId: executeConfig.marketplaceId.toString() } @@ -211,7 +217,7 @@ export async function callExecuteWithOffchain(): Promise { /* let unsignedTx = await bnplContractInstance .populateTransaction - .executeWithOffchainSignatures( + .executeUsingOffchainSignatures( formattedSubmitBidArgs, basicOrderParams, borrowerSignature, diff --git a/tasks/executeReservoirOrder.ts b/tasks/executeReservoirOrder.ts new file mode 100644 index 0000000..1bb3dc4 --- /dev/null +++ b/tasks/executeReservoirOrder.ts @@ -0,0 +1,263 @@ + + + + + + +import { recoverSignerOfOffchainOffer } from '@clarity-credit/anpl-sdk' +import axios from 'axios' +import { toChecksumAddress } from 'ethereumjs-util' +import {Contract, Wallet, providers, utils, BigNumber, ethers} from 'ethers' + +import { getRpcUrlFromNetworkName, networkNameFromChainId } from '../lib/app-helper' + +import { buildExecuteParams, calculateTotalPrice, generateBNPLOrderSignature, performCraRequest, readSignatureVersionFromBNPLMarketContract } from '../lib/bnpl-helper' +import { fetchReservoirOrderById, formatReservoirOrder } from '../lib/reservoir-helper' +import { calculatePrincipalRequiredForBorrowerPayout } from '../lib/teller-v2-lending-helper' + +import { AdditionalRecipient, AdditionalRecipientResponse, BasicOrderParams, DomainData, ReservoirOrder, ReservoirOrderRawData, SubmitBidArgs } from '../lib/types' + +require('dotenv').config() + +const borrowerPrivateKey = process.env.BORROWER_PRIVATE_KEY! + +const lenderPrivateKey = process.env.LENDER_PRIVATE_KEY! + + + +const networkName = 'mainnet' + +let contractsConfig = require('../data/contractsConfig.json')[networkName] + + +const rpcURI = getRpcUrlFromNetworkName(networkName) +const tellerV2Config = { + address: contractsConfig.tellerV2.address, + abi: require('../abi/TellerV2.json') +} +const bnplConfig = { + address: contractsConfig.BNPLContract.address, + abi: require('../abi/BNPLMarketV3.json') +} + +const chainId = "1" +const marketId = "6" + + +/* + +Test w tenderly test RPC + +*/ + + + +export async function executeReservoirOrder(): Promise { + + const orderId = "0x36676cd9406a187400fc3154d3e1e214374e4c907e31eef963b0dcef366cb15b" + + const orderResponse:ReservoirOrder|undefined = await fetchReservoirOrderById({orderId}) + + console.log({orderResponse}) + + if(!orderResponse){ + throw new Error('No matching order from reservoir') + } + + const {basicOrderParams} = formatReservoirOrder( orderResponse ) + + + + if(!basicOrderParams){ + throw new Error('Unable to build basic order params') + } + + + const additionalRecipientsFormatted:AdditionalRecipient[] = basicOrderParams.additionalRecipients.map( (r:any) => {return { + amount: BigNumber.from(r.amount), + recipient: r.recipient + }}) + + const basicOrderParamsFormatted:BasicOrderParams = { + considerationToken: basicOrderParams.considerationToken, + considerationIdentifier: BigNumber.from(basicOrderParams.considerationIdentifier), + considerationAmount: BigNumber.from(basicOrderParams.considerationAmount), + offerer: basicOrderParams.offerer, + zone: basicOrderParams.zone, + offerToken: basicOrderParams.offerToken, + offerIdentifier: BigNumber.from(basicOrderParams.offerIdentifier), + offerAmount: basicOrderParams.offerAmount, + basicOrderType: basicOrderParams.basicOrderType, + startTime: BigNumber.from(basicOrderParams.startTime), + endTime: BigNumber.from(basicOrderParams.endTime), + zoneHash: basicOrderParams.zoneHash, + salt: basicOrderParams.salt, + offererConduitKey: basicOrderParams.offererConduitKey, + fulfillerConduitKey: basicOrderParams.fulfillerConduitKey, + totalOriginalAdditionalRecipients: BigNumber.from(basicOrderParams.totalOriginalAdditionalRecipients), + additionalRecipients: additionalRecipientsFormatted, + signature: basicOrderParams.signature + } + + console.log({rpcURI}) + console.log({bnplConfig}) + + let rpcProvider = new providers.JsonRpcProvider( rpcURI ) + + let tellerV2Instance = new Contract(tellerV2Config.address,tellerV2Config.abi, rpcProvider) + let bnplContractInstance = new Contract(bnplConfig.address,bnplConfig.abi,rpcProvider) + + + + const borrowerWallet = new Wallet(borrowerPrivateKey, rpcProvider) + + + const borrowerAddress = borrowerWallet.address + + + const lenderWallet = new Wallet(lenderPrivateKey,rpcProvider) + + const lenderAddress = lenderWallet.address + + + + + const considerationAmount = BigNumber.from( basicOrderParams.considerationAmount ) + const additionalAmount = calculateTotalAdditionalAmount( basicOrderParams.additionalRecipients ) + const totalPurchasePrice = considerationAmount.add(additionalAmount).toString() + + const downPayment = BigNumber.from(totalPurchasePrice).div(2).toString() + + const amountRequiredForLoan = BigNumber.from(totalPurchasePrice).sub( downPayment ) + + const principal = calculatePrincipalRequiredForBorrowerPayout( + amountRequiredForLoan, + BigNumber.from(0), //market fee for market 6 + BigNumber.from(5) //protocol fee + ).toString() + + + const secondsNow = Math.floor(Date.now()/1000) + + const signatureExpiration = secondsNow + 90*60*1000 + + let submitBidArgs:SubmitBidArgs = { + borrower: borrowerAddress, + lender: lenderAddress, + + + totalPurchasePrice, + principal, + downPayment, + + duration: '28000', + signatureExpiration: signatureExpiration.toString(), + interestRate: '300', + + metadataURI: 'ipfs://', + referralAddress: ethers.constants.AddressZero, + marketId + } + + const implementationContractAddress = bnplConfig.address + //"0x3bf7F0D0FA47F2101f67bd530F1bE7aD05D90321" + + const domainData:DomainData = { + name: 'Teller_BNPL_Market', + version: '3.5', + chainId: parseInt(chainId), + verifyingContract: implementationContractAddress + } + + + + //fix it for now to remove referral and sig expir + let formattedSubmitBidArgs:SubmitBidArgs = { + borrower: borrowerAddress, + lender: lenderAddress, + totalPurchasePrice: submitBidArgs.totalPurchasePrice, + principal: submitBidArgs.principal, + downPayment: submitBidArgs.downPayment, + duration: submitBidArgs.duration, + signatureExpiration: submitBidArgs.signatureExpiration, + interestRate:submitBidArgs.interestRate, + metadataURI: submitBidArgs.metadataURI , + referralAddress: submitBidArgs.referralAddress, + marketId + } + + + + let borrowerSignature = await generateBNPLOrderSignature( + formattedSubmitBidArgs, + basicOrderParamsFormatted, + domainData, + borrowerWallet, + ) + + let lenderSignature = await generateBNPLOrderSignature( + formattedSubmitBidArgs, + basicOrderParamsFormatted, + domainData, + lenderWallet, + ) + + + let recoveredSigner = recoverSignerOfOffchainOffer( + formattedSubmitBidArgs, + basicOrderParamsFormatted, + domainData, + lenderSignature + ) + + console.log({recoveredSigner}) + + console.log(JSON.stringify(basicOrderParamsFormatted)) + console.log(JSON.stringify(formattedSubmitBidArgs)) + + + //Set price to 1 Gwei + let gasPrice = utils.hexlify(8_000_000_000); + //Set max gas limit to 4M + var gasLimit = utils.hexlify(10_000_000); + + + + console.log({borrowerSignature},{lenderSignature}) + + let unsignedTx = await bnplContractInstance + .populateTransaction + .executeUsingOffchainSignatures( + formattedSubmitBidArgs, + basicOrderParamsFormatted, + borrowerSignature, + lenderSignature + , { gasLimit, gasPrice} ) + + + console.log('made unsigned tx') + + let response = await borrowerWallet.sendTransaction(unsignedTx); + console.log('response',response) + + + + return true + } + + + + + + + + function calculateTotalAdditionalAmount( additionalRecipients: AdditionalRecipientResponse[] ) : BigNumber { + + let result = BigNumber.from(0) + + additionalRecipients.map( (r:any) => result = result.add(r.amount)) + + return result + + + } \ No newline at end of file diff --git a/tasks/index.ts b/tasks/index.ts index b939cce..0a271ba 100644 --- a/tasks/index.ts +++ b/tasks/index.ts @@ -8,6 +8,7 @@ import { approveMarket } from './approveMarket' import {getNFTsOwned} from './getNFTsOwned' import {callExecuteWithOffchain} from './callExecuteWithOffchain' import {submitOffchainOffer} from './submitOffchainOffer' +import {executeReservoirOrder} from './executeReservoirOrder' const yargs = require('yargs').argv @@ -19,7 +20,8 @@ const taskMap: any = { fetchCraResponse, approveMarket, getNFTsOwned, - submitOffchainOffer + submitOffchainOffer, + executeReservoirOrder // matchOrder } diff --git a/tasks/submitDiscrete.ts b/tasks/submitDiscrete.ts index a3397c2..888df08 100644 --- a/tasks/submitDiscrete.ts +++ b/tasks/submitDiscrete.ts @@ -120,6 +120,7 @@ export async function submitDiscrete(): Promise { interestRate:submitBidArgs.interestRate, referralAddress: submitBidArgs.referralAddress, metadataURI: submitBidArgs.metadataURI , + marketId: "2" } diff --git a/tasks/submitOffchainOffer.ts b/tasks/submitOffchainOffer.ts index 2eaa5d8..8521eaf 100644 --- a/tasks/submitOffchainOffer.ts +++ b/tasks/submitOffchainOffer.ts @@ -150,6 +150,7 @@ export async function submitOffchainOffer(): Promise { interestRate:submitBidArgs.interestRate, referralAddress: submitBidArgs.referralAddress, metadataURI: submitBidArgs.metadataURI , + marketId:"2" } let borrowerSignature = await signOffchainOffer({ diff --git a/yarn.lock b/yarn.lock index df6b388..e9d1eaf 100644 --- a/yarn.lock +++ b/yarn.lock @@ -113,10 +113,10 @@ ethers "~4.0.4" lodash "^4.17.11" -"@clarity-credit/anpl-sdk@^0.1.3": - version "0.1.8" - resolved "https://registry.yarnpkg.com/@clarity-credit/anpl-sdk/-/anpl-sdk-0.1.8.tgz#ddc65305aac7bb6d351025796b27b84e3d5aea67" - integrity sha512-WIQEkN31RrU/QEmRgrGosjEyhdQ2TfTbk6erC8hfw58OTPvXjBla4snzs1h9NtBLu1uhH0IH4huRCRwGpYBkIw== +"@clarity-credit/anpl-sdk@^0.3.5": + version "0.3.5" + resolved "https://registry.yarnpkg.com/@clarity-credit/anpl-sdk/-/anpl-sdk-0.3.5.tgz#2dd7757da20ef96706c780d86372f0fac3859097" + integrity sha512-4f5ixYOOU6p//oDRhUf3/4JWGfDfQHbWDmIdc5xp2NQTjSJ5IGrRiVClVDvAZ5RomF8WJLVqbuAfAAVJZx837w== dependencies: ethers "^5.7.1" @@ -1480,10 +1480,10 @@ axios@^0.26.1: dependencies: follow-redirects "^1.14.8" -axios@^1.2.0: - version "1.2.0" - resolved "https://registry.yarnpkg.com/axios/-/axios-1.2.0.tgz#1cb65bd75162c70e9f8d118a905126c4a201d383" - integrity sha512-zT7wZyNYu3N5Bu0wuZ6QccIf93Qk1eV8LOewxgjOZFd2DenOs98cJ7+Y6703d0wkaXGY6/nZd4EweJaHz9uzQw== +axios@^1.2.3: + version "1.2.3" + resolved "https://registry.yarnpkg.com/axios/-/axios-1.2.3.tgz#31a3d824c0ebf754a004b585e5f04a5f87e6c4ff" + integrity sha512-pdDkMYJeuXLZ6Xj/Q5J3Phpe+jbGdsSzlQaFVkMQzRUL05+6+tetX8TV3p4HrU4kzuO9bt+io/yGQxuyxA/xcw== dependencies: follow-redirects "^1.15.0" form-data "^4.0.0"