-
Notifications
You must be signed in to change notification settings - Fork 12
/
conditionalSR.js
159 lines (143 loc) · 5.61 KB
/
conditionalSR.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
/***
* conditionalSR API
* @module conditionalSR
*/
const internal = require('./internal/conditionalSR');
/**
* Return the details of a commitment.
* @param {Object} contracts - An Urbit contracts object.
* @param {String} address - The participant/registered address for the
* commitment.
* @return {Promise<Object>} A commitment object, with windup, rate, rateUnit,
* amount, withdrawn.
*/
module.exports.getCommitment = internal.getCommitment;
/**
* Return the list of stars that have been deposited into, but not yet
* withdrawn from a commitment.
* @param {Object} contracts - An Urbit contracts object.
* @param {String} address - The participant/registered address for the
* commitment.
* @return {Promise<Array<Number>>} The stars left in the commitment.
*/
module.exports.getRemainingStars = internal.getRemainingStars;
/**
* Return the configured sizes of the batches for the commitment.
* @param {Object} contracts - An Urbit contracts object.
* @param {String} address - The participant/registered address for the
* commitment.
* @return {Promise<Array<Number>>} The batch sizes for the commitment.
*/
module.exports.getBatches = internal.getBatches;
/**
* Return whether the amount of stars deposited into the commitment checks out.
* @param {Object} contracts - An Urbit contracts object.
* @param {String} address - The participant/registered address for the
* commitment.
* @return {Promise<Bool>} true if sufficient stars have been deposited.
*/
module.exports.verifyBalance = internal.verifyBalance;
/**
* Return the timestamp at which the release was started.
* @param {Object} contracts - An Urbit contracts object.
* @return {Promise<Number>} A timestamp.
*/
module.exports.getStartTime = internal.getStartTime;
/**
* Return the amount of stars a participant has already withdrawn from
* each of their batches at the current time
* @param {Object} contracts - An Urbit contracts object.
* @param {String} address - The participant/registered address for the
* commitment.
* @return {Promise<Array<Number>>} the number of stars already withdrawn for
* each batch.
*/
module.exports.getWithdrawn = internal.getWithdrawn;
/**
* Return the amount of stars a participant is allowed to withdraw from
* one of their batches at the current time.
* @param {Object} contracts - An Urbit contracts object.
* @param {String} address - The participant/registered address for the
* commitment.
* @param {Number} batch - The batch number to look up
* @return {Promise<Number>} the withdraw limit.
*/
module.exports.getWithdrawLimit = internal.getWithdrawLimit;
/**
* Return the address this commitment can be transferred to.
* @param {Object} contracts - An Urbit contracts object.
* @param {String} address - The participant/registered address for the
* commitment.
* @return {Promise<String>} The approved transfer address, 0x0 for none.
*/
module.exports.getApprovedTransfer = internal.getApprovedTransfer;
/**
* Return conditions configuration and state data.
* @param {Object} contracts - An Urbit contracts object.
* @return {Promise<Object>} An object containing conditions state, with
* { conditions, livelines, deadlines, timestamps } arrays.
*/
module.exports.getConditionsState = async function(contracts) {
let { conds, deads, lives, times } = await internal.getConditionsState(
contracts
);
return {
conditions: conds,
livelines: lives,
deadlines: deads,
timestamps: times
};
};
/**
* Return whether or not each of the batches have been forfeited at the
* current time.
* @param {Object} contracts - An Urbit contracts object.
* @param {String} address - The participant/registered address for the
* commitment.
* @return {Promise<Array<Bool>>} the number of stars already withdrawn for
* each batch.
*/
module.exports.getForfeited = internal.getForfeited;
/**
* Approve the transfer of a commitment to another address.
* @param {Object} contracts - An Urbit contracts object.
* @param {String} address - The address to transfer to.
* @return {Promise<Object>} An unsigned transaction object.
*/
module.exports.approveCommitmentTransfer = internal.approveCommitmentTransfer;
/**
* Make an approved transfer of the specified commitment to the caller's address.
* @param {Object} contracts - An Urbit contracts object.
* @param {String} address - The address to transfer from.
* @return {Object} An unsigned transaction object.
*/
module.exports.transferCommitment = internal.transferCommitment;
/**
* Withdraw one star from a batch to the caller's address.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} batch - The batch number to withdraw from
* @return {Object} An unsigned transaction object.
*/
module.exports.withdraw = internal.withdraw;
/**
* Withdraw one star from a batch to the specified address.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} batch - The batch number
* @param {String} address - The address to withdraw to.
* @return {Object} An unsigned transaction object.
*/
module.exports.withdrawTo = internal.withdrawTo;
/**
* Forfeit stars contained in a batch with missed deadline, and all after it.
* @param {Object} contracts - An Urbit contracts object.
* @param {Number} batch - The condition/batch to base forfeiture off.
* @return {Object} An unsigned transaction object.
*/
module.exports.forfeit = internal.forfeit;
/**
* Analyze a condition for satisfaction.
* @param {Object} contracts - An Urbit contracts object.
* @param {String} condition - The condition (index) to analyze.
* @return {Object} An unsigned transaction object.
*/
module.exports.analyzeCondition = internal.analyzeCondition;