-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from 00labs/allow-separate-metadata-uploads
Split out metadata uploading from ReceivableService.createReceivableWithMetadata
- Loading branch information
Showing
25 changed files
with
646 additions
and
364 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
REACT_APP_INFURA_API_KEY= | ||
REACT_APP_ALCHEMY_API_KEY= | ||
TEST_PRIVATE_KEY= | ||
REACT_APP_ALCHEMY_API_KEY_2= | ||
TEST_PRIVATE_KEY= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
import { Wallet, ethers } from "ethers"; | ||
import { | ||
ARWeaveService, | ||
ReceivableService, | ||
getBundlrNetworkConfig, | ||
} from "@huma-finance/sdk"; | ||
import { ChainEnum, POOL_NAME, POOL_TYPE } from "@huma-finance/shared"; | ||
require("dotenv").config(); | ||
|
||
/* | ||
* We use Bundlr to upload metadata to ARWeave, which allows for users to pay in popular currencies like MATIC or ETH | ||
* instead of AR tokens. Certain networks that are still unsupported by Bundlr (e.g. Celo) can still use Bundlr to | ||
* fund the ARWeave uploads by simply paying on a supported network. | ||
* | ||
* This snippet shows how to use a wallet with MATIC to fund the ARWeave uploads, and then that same wallet on | ||
* a separate network to upload a RealWorldReceivable with the resulting metadata URI. | ||
*/ | ||
async function main() { | ||
const TEST_PRIVATE_KEY = process.env.TEST_PRIVATE_KEY; | ||
|
||
// We'll be using a mumbai wallet funded with MATIC to pay for the ARWeave uploads | ||
const mumbaiProvider = new ethers.providers.JsonRpcProvider( | ||
`https://polygon-mumbai.g.alchemy.com/v2/${process.env.REACT_APP_ALCHEMY_API_KEY}`, | ||
{ | ||
name: "Mumbai", | ||
chainId: ChainEnum.Mumbai, | ||
} | ||
); | ||
const walletOnSupportedBundlrNetwork = new Wallet( | ||
TEST_PRIVATE_KEY, | ||
mumbaiProvider | ||
); | ||
|
||
// On a separate network which may not be supported by Bundlr, we'll use our wallet | ||
// to create a RealWorldReceivable with the metadata URI from ARWeave | ||
const rwrProvider = new ethers.providers.JsonRpcProvider( | ||
`https://eth-goerli.g.alchemy.com/v2/${process.env.REACT_APP_ALCHEMY_API_KEY_2}`, | ||
{ | ||
name: "Goerli", | ||
chainId: ChainEnum.Goerli, | ||
} | ||
); | ||
const walletOnRWRNetwork = new Wallet(TEST_PRIVATE_KEY, rwrProvider); | ||
|
||
console.log( | ||
`Using ${walletOnSupportedBundlrNetwork.address} to upload metadata` | ||
); | ||
console.log( | ||
`Using ${walletOnRWRNetwork.address} to create RealWorldReceivable` | ||
); | ||
|
||
// Prefund Bundlr with MATIC | ||
const fundResponse = await ARWeaveService.prefundBundlr( | ||
getBundlrNetworkConfig(ChainEnum.Mumbai), | ||
TEST_PRIVATE_KEY, | ||
0.05 // Fund with 0.05 matic | ||
); | ||
console.log(fundResponse); | ||
|
||
const uri = await ReceivableService.uploadOrFetchMetadataURI( | ||
walletOnSupportedBundlrNetwork, | ||
TEST_PRIVATE_KEY, | ||
ChainEnum.Mumbai, | ||
POOL_NAME.HumaCreditLine, | ||
POOL_TYPE.CreditLine, | ||
JSON.parse('{"test": "test"}'), // metadata | ||
"1234567", // referenceId | ||
[{ name: "indexedIdentifier", value: "exampleValue" }] // extraTags | ||
); | ||
|
||
// Mint a receivable with metadata uploaded to ARWeave | ||
const tx = await ReceivableService.createReceivable( | ||
walletOnRWRNetwork, | ||
POOL_NAME.HumaCreditLine, | ||
POOL_TYPE.CreditLine, | ||
840, // currencyCode for USD | ||
1000, // receivableAmount | ||
1684517656, // maturityDate | ||
uri // metadataURI | ||
); | ||
const txResponse = await tx.wait(); | ||
console.log(`Success. Tx hash: ${txResponse.transactionHash}`); | ||
} | ||
|
||
main(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.