😎
Cheat Sheet
One-liners to keep you "in the flow".

Quick-start

Setup the SDK in Truffle console and mint DAIx. See the tutorial for a full walk-through.

Tokens

balanceOf()
1
(await daix.balanceOf(bob)).toString() / 1e18
2
(await dai.balanceOf(bob)).toString() / 1e18
3
​
4
or
5
​
6
(async () => wad4human(await dai.balanceOf(bob))()
7
(async () => wad4human(await daix.balanceOf(bob))()
Copied!
upgrade()
1
dai.approve(daix.address, "1" + "0".repeat(42), { from: bob });
2
daix.upgrade(web3.utils.toWei("50", "ether"), { from: bob });
Copied!

User Class

user()
1
const bob = sf.user({ address: bobAddress, token: daix.address });
2
const alice = sf.user({ address: aliceAddress, token: daix.address });
Copied!
bob.details()
1
const details = await bob.details();
2
​
3
// returns an object
4
details: {
5
cfa: {
6
flows: {
7
inFlows: [
8
{ sender, receiver, flowRate }
9
],
10
outFlows: [
11
{ sender, receiver, flowRate }
12
]
13
},
14
netFlow: ""
15
}
16
ida: {
17
subscriptions: []
18
}
Copied!

Agreements

Constant Flow Agreement (CFA)

A CFA is a transfer of value from a sender to a receiver at a constant flowRate measured in amount per second.

User Class (easy mode)

bob.flow()
1
// create new flow
2
bob.flow({ recipient: alice, flowRate: "-38580246913580" }); //recipient can be user object or address
3
​
4
// edit existing flow
5
bob.flow({ recipient: alice.address, flowRate: 0.1 * 1e18 }); //0.1 DAI per second with 18 decimals.
6
​
7
// close flow
8
bob.flow({ recipient: alice, flowRate: "0" });
9
​
10
// add custom userData parameters
11
const userData = { message: "here's a flow Alice", flowId: "007" };
12
bob.flow({ recipient: alice, flowRate: 1 * 1e18, options: { userData } });
Copied!

Agreement Helper Class (hard mode)

createFlow()
1
sf.cfa.createFlow({
2
superToken: daix.address,
3
sender: bob,
4
receiver: alice,
5
flowRate: "385802469135802"
6
});
Copied!
updateFlow()
1
sf.cfa.updateFlow({
2
superToken: daix.address,
3
sender: bob,
4
receiver: alice,
5
flowRate: "632802469135333"
6
});
Copied!
deleteFlow()
1
sf.cfa.deleteFlow({superToken: daix.address, sender: bob, receiver: alice, by: bob})
Copied!
getNetFlow()
1
(await sf.cfa.getNetFlow({superToken: daix.address, account: bob})).toString()
Copied!
getFlow()
1
(await sf.cfa.getFlow({superToken: daix.address, sender: bob, receiver: alice})).toString()
Copied!
listFlows()
1
await sf.cfa.listFlows({superToken: daix.address, account: bob})
Copied!

Instant Distribution Agreement (IDA)

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.

User Class (easy mode)

bob.createPool()
1
await bob.createPool({ poolId: 1 });
Copied!
bob.giveShares()
1
await bob.giveShares({ poolId: 1, recipient: alice, shares: 90 });
2
await bob.giveShares({ poolId: 1, recipient: carol, shares: 10 });
Copied!
bob.distributeToPool()
1
await bob.distributeToPool({ poolId: 1, amount: 1000 });
Copied!

Agreement Helper Class (hard mode)

createIndex() (sent from publisher)
1
sf.ida.createIndex({
2
superToken: daix.address,
3
indexId: 1,
4
sender: bob.address
5
});
Copied!
updateSubscription() (sent from publisher)
1
sf.ida.updateSubscription({
2
superToken: daix.address,
3
indexId: 1,
4
subscriber: carol.address, //who is receiving the units
5
sender: bob.address, //the publisher
6
units: "100"
7
});
Copied!
approveSubscription() (sent from subscriber)
1
sf.ida.approveSubscription({
2
superToken: daix.address,
3
indexId: 1,
4
publisher: bob.address, // the publisher
5
subscriber: carol.address // who is receiving the units and sending this tx
6
});
Copied!
distribute() (sent from publisher)
1
sf.ida.distribute({
2
superToken: daix.address,
3
indexId: 1,
4
amount: 100 * 1e18, // amount to distribute
5
sender: bob.address // the Publisher
6
});
Copied!
claim() (sent from subscriber)
1
sf.ida.claim({
2
superToken: daix.address,
3
publisher: bob.address,
4
indexId: 1,
5
subscriber: carol.address,
6
sender: carol.address // because ANYONE can send this tx
7
});
Copied!
Last modified 3mo ago