Last active
January 19, 2022 23:49
-
-
Save jtriley-eth/837510cf5a40547670c540287b820813 to your computer and use it in GitHub Desktop.
IDAv1 Batch Call
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
import { Framework } from '@superfluid-finance/sdk-core' | |
import { ethers } from 'ethers' | |
// extracted from `./.env` | |
const apiKey = process.env.API_KEY | |
const privateKey = process.env.PRIV_KEY | |
// intializing | |
const provider = new ethers.providers.InfuraProvider('matic', apiKey) | |
const sf = await Framework.create({ networkName: 'matic', provider }) | |
const signer = sf.createSigner({ privateKey, provider }) | |
const usdcx = await sf.loadSuperToken('0xCAa7349CEA390F89641fe306D93591f87595dc1F') | |
// your address here | |
const publisher = '0xf398...' | |
// subscriber addresses here | |
const alice = '0x8BfF...' | |
const bob = '0xB8B9...' | |
const charlie = '0x8a97...' | |
// operations | |
const createIndexOp = usdcx.createIndex({ indexId: 0 }) | |
const updateSubscriptionOp0 = usdcx.updateSubscriptionUnits({ | |
indexId: 0, | |
subscriber: alice, | |
units: 7 | |
}) | |
const updateSubscriptionOp1 = usdcx.updateSubscriptionUnits({ | |
indexId: 0, | |
subscriber: bob, | |
units: 2 | |
}) | |
const updateSubscriptionOp2 = usdcx.updateSubscriptionUnits({ | |
indexId: 0, | |
subscriber: charlie, | |
units: 1 | |
}) | |
// batch the operations | |
const batchCall = sf.batchCall( | |
[ | |
createIndexOp, | |
updateSubscriptionOp0, | |
updateSubscriptionOp1, | |
updateSubscriptionOp2 | |
] | |
) | |
// run the batch call transaction | |
const transaction = await batchCall.exec(signer) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment