on master help sign in
Merge pull request #402 from urbit/m/release-deposit-fix
e15d0c1Fang
package-lock.json+3−3
@@ -2653,9 +2653,9 @@
2653 }
2653 }
2654 },
2654 },
2655 "azimuth-js": {
2655 "azimuth-js": {
2656− "version": "0.17.0",
2656+ "version": "0.18.0",
2657− "resolved": "https://registry.npmjs.org/azimuth-js/-/azimuth-js-0.17.0.tgz",
2657+ "resolved": "https://registry.npmjs.org/azimuth-js/-/azimuth-js-0.18.0.tgz",
2658− "integrity": "sha512-g1/4gfhMHrj6NjCp96c5FBS202nIBnGiXcGTl9i0kh3rB6AE85rd0Un+z+qOhrVJbUdJF0axTvw3xsB5o5u+7Q==",
2658+ "integrity": "sha512-i8mkXIfWN9GKQcd8KsjQNbf393HVOadIMN6v40KgRnMIjM6dMgUP5zoEbCsG2Zn0SgLRgw0kiNyXHGVitdumiw==",
2659 "requires": {
2659 "requires": {
2660 "azimuth-solidity": "1.2.1",
2660 "azimuth-solidity": "1.2.1",
2661 "ethereumjs-util": "^5.2.0",
2661 "ethereumjs-util": "^5.2.0",
package.json+1−1
@@ -19,7 +19,7 @@
19 "@ledgerhq/hw-transport-u2f": "^5.5.0",
19 "@ledgerhq/hw-transport-u2f": "^5.5.0",
20 "@welldone-software/why-did-you-render": "^3.2.3",
20 "@welldone-software/why-did-you-render": "^3.2.3",
21 "async-retry": "^1.2.3",
21 "async-retry": "^1.2.3",
22− "azimuth-js": "^0.17.0",
22+ "azimuth-js": "^0.18.0",
23 "azimuth-solidity": "^1.2.0",
23 "azimuth-solidity": "^1.2.0",
24 "bip32": "^1.0.2",
24 "bip32": "^1.0.2",
25 "bip39": "^2.5.0",
25 "bip39": "^2.5.0",
src/lib/starRelease.js+35−11
@@ -65,21 +65,36 @@ function generateLinearWithdrawTxs(contracts, amount, to) {
65}
65}
66
66
67export async function getConditional(contracts, address) {
67export async function getConditional(contracts, address) {
68− const [commitment, batches] = await Promise.all([
68+ const [commitment, batches, remaining] = await Promise.all([
69 conditionalSR.getCommitment(contracts, address),
69 conditionalSR.getCommitment(contracts, address),
70 conditionalSR.getBatches(contracts, address),
70 conditionalSR.getBatches(contracts, address),
71+ conditionalSR.getRemainingStars(contracts, address),
71 ]);
72 ]);
72
73
73 if (commitment === null || batches === null) {
74 if (commitment === null || batches === null) {
74 return { total: 0, available: 0, withdrawn: 0, batchLimits: [] };
75 return { total: 0, available: 0, withdrawn: 0, batchLimits: [] };
75 }
76 }
76
77
77− const { total } = commitment;
78+ const forfeited = await conditionalSR.getForfeited(contracts, address);
79+ const total = remaining.length;
80+ let balance = total;
81+
78− const withdrawLimits = await Promise.all(
82+ const withdrawLimits = await batches.reduce(async (p, _, idx) => {
79− batches.map((_, idx) =>
83+ const acc = await p;
84+ if (forfeited[idx] || balance === 0) {
85+ return [...acc, 0];
86+ }
80− conditionalSR.getWithdrawLimit(contracts, address, idx)
87+ const limit = await conditionalSR.getWithdrawLimit(contracts, address, idx);
81− )
88+ if (limit <= balance) {
82− );
89+ balance -= limit;
90+ return [...acc, limit];
91+ }
92+ const remaining = balance;
93+ balance = 0;
94+
95+ return [...acc, remaining];
96+ }, Promise.resolve([]));
97+
83 const available = withdrawLimits.reduce((acc, val) => acc + val, 0);
98 const available = withdrawLimits.reduce((acc, val) => acc + val, 0);
84
99
85 const withdrawnAmounts = await conditionalSR.getWithdrawn(contracts, address);
100 const withdrawnAmounts = await conditionalSR.getWithdrawn(contracts, address);
@@ -93,9 +108,18 @@ export async function getConditional(contracts, address) {
93}
108}
94
109
95export async function getLinear(contracts, address) {
110export async function getLinear(contracts, address) {
111+ const remaining = (await linearSR.getRemainingStars(contracts, address))
112+ .length;
113+ const batch = await linearSR.getBatch(contracts, address);
114+ const { amount, withdrawn } = batch;
115+
116+ // Contract errors on withdrawing from a user that does not have any
117+ const available =
118+ amount > 0
96− const { amount, withdrawn } = await linearSR.getBatch(contracts, address);
119+ ? Math.min(await linearSR.getWithdrawLimit(contracts, address), remaining)
120+ : 0;
121+
122+ const total = Math.min(amount, remaining);
97
123
98− const available = // Contract errors on withdrawing from a user that does not have any
99− amount > 0 ? await linearSR.getWithdrawLimit(contracts, address) : 0;
100− return { available, withdrawn, total: amount };
124+ return { available, withdrawn, total };
101}
125}