Setup the SDK in Truffle console and mint DAIx. See the tutorial for a full walk-through.
balanceOf()
(await daix.balanceOf(bob)).toString() / 1e18(await dai.balanceOf(bob)).toString() / 1e18or(async () => wad4human(await dai.balanceOf(bob))()(async () => wad4human(await daix.balanceOf(bob))()
upgrade()
dai.approve(daix.address, "1" + "0".repeat(42), { from: bob });daix.upgrade(web3.utils.toWei("50", "ether"), { from: bob });
user()
const bob = sf.user({ address: bobAddress, token: daix.address });const alice = sf.user({ address: aliceAddress, token: daix.address });
bob.details()
const details = await bob.details();// returns an objectdetails: {cfa: {flows: {inFlows: [{ sender, receiver, flowRate }],outFlows: [{ sender, receiver, flowRate }]},netFlow: ""}ida: {subscriptions: []}
A CFA is a transfer of value from a sender
to a receiver
at a constant flowRate
measured in amount per second.
bob.flow()
// create new flowbob.flow({ recipient: alice, flowRate: "-38580246913580" }); //recipient can be user object or address// edit existing flowbob.flow({ recipient: alice.address, flowRate: 0.1 * 1e18 }); //0.1 DAI per second with 18 decimals.// close flowbob.flow({ recipient: alice, flowRate: "0" });// add custom userData parametersconst userData = { message: "here's a flow Alice", flowId: "007" };bob.flow({ recipient: alice, flowRate: 1 * 1e18, options: { userData } });
createFlow()
sf.cfa.createFlow({superToken: daix.address,sender: bob,receiver: alice,flowRate: "385802469135802"});
updateFlow()
sf.cfa.createFlow({superToken: daix.address,sender: bob,receiver: alice,flowRate: "632802469135333"});
deleteFlow()
sf.cfa.deleteFlow({superToken: daix.address, sender: bob, receiver: alice, by: bob})
getNetFlow()
(await sf.cfa.getNetFlow({superToken: daix.address, account: bob})).toString()
getFlow()
(await sf.cfa.getFlow({superToken: daix.address, sender: bob, receiver: alice})).toString()
listFlows()
await sf.cfa.listFlows({superToken: daix.address, account: bob})
An IDA is used to send funds as one-time-payments. It consists of a Publishing Index with indexId
, an indexValue
which is updated every time distribute()
is called, and one or more subscribers.
Remember there is one distributor, and many subscribers.
bob.createPool()
await bob.createPool({ poolId: 1 });
bob.giveShares()
await bob.giveShares({ poolId: 1, recipient: alice, shares: 90 });await bob.giveShares({ poolId: 1, recipient: carol, shares: 10 });
bob.distributeToPool()
await bob.distributeToPool({ poolId: 1, amount: 1000 });
createIndex()
(sent from publisher)
sf.ida.createIndex({superToken: daix.address,indexId: 1,sender: bob.address});
updateSubscription()
(sent from publisher)
sf.ida.updateSubscription({superToken: daix.address,indexId: 1,subscriber: carol.address, //who is receiving the unitssender: bob.address, //the publisherunits: "100"});
approveSubscription()
(sent from subscriber)
sf.ida.approveSubscription({superToken: daix.address,indexId: 1,publisher: bob.address, // the publishersender: carol.address // who is receiving the units and sending this tx});
distribute()
(sent from publisher)
sf.ida.distribute({superToken: daix.address,indexId: 1,amount: 100 * 1e18, // amount to distributesender: bob.address // the Publisher});
claim()
(sent from subscriber)
sf.ida.claim({superToken: daix.address,publisher: bob.address,indexId: 1,subscriber: carol.address,sender: carol.address // because ANYONE can send this tx});