Skip to content

Commit 6f12652

Browse files
committed
fix: merge conflicts
2 parents 1c248f4 + b169a3b commit 6f12652

37 files changed

+1922
-654
lines changed

‎./workflows/check-PRs.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -71,15 +71,15 @@ jobs:
7171
docker-compose build
7272
./start-nightfall -wt -s &
7373
74-
- name: wait 1500s for Containers startup and setup completion
75-
run: sleep 1500
74+
- name: wait 2500s for Containers startup and test completion
75+
run: sleep 2500
7676

7777
- name: Retrieve Wallet test logs
78-
run: docker logs $(docker ps -aqf "name=wallet-test") > wallet-test.log
78+
run: docker logs $(docker ps -aqf "name=wallet-test") > wallet-test.log; cat wallet-test.log;
7979

8080
- name: debug logs - after container startup
8181
if: always()
82-
run: results=$(cat wallet-test.log | grep PASSED); cat wallet-test.log; if [ ! -z "${results}" ]; then exit 0; else exit 1; fi
82+
run: if [ -z "$(cat wallet-test.log | grep FAILED)" ]; then exit 0; else exit 1; fi
8383

8484
- name: If integration test failed, shutdown the Containers
8585
if: failure()

‎cli/lib/nf3.mjs

+42-13
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class Nf3 {
8282
@returns {Promise}
8383
*/
8484
async init(mnemonic) {
85-
this.setWeb3Provider();
85+
await this.setWeb3Provider();
8686
this.shieldContractAddress = await this.getContractAddress('Shield');
8787
this.proposersContractAddress = await this.getContractAddress('Proposers');
8888
this.challengesContractAddress = await this.getContractAddress('Challenges');
@@ -279,11 +279,14 @@ class Nf3 {
279279
tokenType,
280280
value,
281281
this.web3,
282+
!!this.ethereumSigningKey,
282283
);
283284
} catch (err) {
284285
throw new Error(err);
285286
}
286-
if (txDataToSign) await this.submitTransaction(txDataToSign, ercAddress, 0);
287+
if (txDataToSign) {
288+
await this.submitTransaction(txDataToSign, ercAddress, 0);
289+
}
287290
const res = await axios.post(`${this.clientBaseUrl}/deposit`, {
288291
ercAddress,
289292
tokenId,
@@ -728,12 +731,20 @@ class Nf3 {
728731
Returns the balance of tokens held in layer 2
729732
@method
730733
@async
734+
@param {Array} ercList - list of erc contract addresses to filter.
735+
@param {Boolean} filterByCompressedPkd - flag to indicate if request is filtered
736+
ones compressed pkd
731737
@returns {Promise} This promise resolves into an object whose properties are the
732738
addresses of the ERC contracts of the tokens held by this account in Layer 2. The
733739
value of each propery is the number of tokens originating from that contract.
734740
*/
735-
async getLayer2Balances() {
736-
const res = await axios.get(`${this.clientBaseUrl}/commitment/balance`);
741+
async getLayer2Balances(ercList, filterByCompressedPkd) {
742+
const res = await axios.get(`${this.clientBaseUrl}/commitment/balance`, {
743+
params: {
744+
compressedPkd: filterByCompressedPkd === true ? this.zkpKeys.compressedPkd : null,
745+
ercList,
746+
},
747+
});
737748
return res.data.balance;
738749
}
739750

@@ -747,9 +758,11 @@ class Nf3 {
747758
value of each propery is the number of tokens originating from that contract.
748759
*/
749760
async getLayer2BalancesDetails(ercList) {
750-
const res = await axios.post(`${this.clientBaseUrl}/commitment/balance-details`, {
751-
compressedPkd: this.zkpKeys.compressedPkd,
752-
ercList,
761+
const res = await axios.get(`${this.clientBaseUrl}/commitment/balance-details`, {
762+
params: {
763+
compressedPkd: this.zkpKeys.compressedPkd,
764+
ercList,
765+
},
753766
});
754767
return res.data.balance;
755768
}
@@ -758,26 +771,42 @@ class Nf3 {
758771
Returns the balance of tokens held in layer 2
759772
@method
760773
@async
774+
@param {Array} ercList - list of erc contract addresses to filter.
775+
@param {Boolean} filterByCompressedPkd - flag to indicate if request is filtered
776+
ones compressed pkd
761777
@returns {Promise} This promise resolves into an object whose properties are the
762778
addresses of the ERC contracts of the tokens held by this account in Layer 2. The
763779
value of each propery is the number of tokens pending deposit from that contract.
764780
*/
765-
async getLayer2PendingDepositBalances() {
766-
const res = await axios.get(`${this.clientBaseUrl}/commitment/pending-deposit`);
781+
async getLayer2PendingDepositBalances(ercList, filterByCompressedPkd) {
782+
const res = await axios.get(`${this.clientBaseUrl}/commitment/pending-deposit`, {
783+
params: {
784+
compressedPkd: filterByCompressedPkd === true ? this.zkpKeys.compressedPkd : null,
785+
ercList,
786+
},
787+
});
767788
return res.data.balance;
768789
}
769790

770791
/**
771792
Returns the balance of tokens held in layer 2
772793
@method
773794
@async
795+
@param {Array} ercList - list of erc contract addresses to filter.
796+
@param {Boolean} filterByCompressedPkd - flag to indicate if request is filtered
797+
ones compressed pkd
774798
@returns {Promise} This promise resolves into an object whose properties are the
775799
addresses of the ERC contracts of the tokens held by this account in Layer 2. The
776800
value of each propery is the number of tokens pending spent (transfer & withdraw)
777801
from that contract.
778802
*/
779-
async getLayer2PendingSpentBalances() {
780-
const res = await axios.get(`${this.clientBaseUrl}/commitment/pending-spent`);
803+
async getLayer2PendingSpentBalances(ercList, filterByCompressedPkd) {
804+
const res = await axios.get(`${this.clientBaseUrl}/commitment/pending-spent`, {
805+
params: {
806+
compressedPkd: filterByCompressedPkd === true ? this.zkpKeys.compressedPkd : null,
807+
ercList,
808+
},
809+
});
781810
return res.data.balance;
782811
}
783812

@@ -810,14 +839,14 @@ class Nf3 {
810839
/**
811840
Set a Web3 Provider URL
812841
*/
813-
setWeb3Provider() {
842+
async setWeb3Provider() {
814843
this.web3 = new Web3(this.web3WsUrl);
815844
this.web3.eth.transactionBlockTimeout = 200;
816845
this.web3.eth.transactionConfirmationBlocks = 12;
817846
if (typeof window !== 'undefined') {
818847
if (window.ethereum && this.ethereumSigningKey === '') {
819848
this.web3 = new Web3(window.ethereum);
820-
window.ethereum.request({ method: 'eth_accounts' });
849+
await window.ethereum.request({ method: 'eth_requestAccounts' });
821850
} else {
822851
// Metamask not available
823852
throw new Error('No Web3 provider found');

‎cli/lib/tokens.mjs

+16-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,15 @@ Sends an approve transaction to an ERC20/ERC721/ERC1155 contract for a certain a
1313
* @param {object} provider - web3 provider
1414
* @returns {Promise} transaction
1515
*/
16-
async function approve(ercAddress, ownerAddress, spenderAddress, tokenType, value, provider) {
16+
async function approve(
17+
ercAddress,
18+
ownerAddress,
19+
spenderAddress,
20+
tokenType,
21+
value,
22+
provider,
23+
encodeABI,
24+
) {
1725
const abi = getAbi(tokenType);
1826
const ercContract = new provider.eth.Contract(abi, ercAddress);
1927

@@ -23,7 +31,7 @@ async function approve(ercAddress, ownerAddress, spenderAddress, tokenType, valu
2331
const allowanceBN = new Web3.utils.BN(allowance);
2432
const valueBN = new Web3.utils.BN(value);
2533
if (allowanceBN.lt(valueBN)) {
26-
if (process.env.USER_ETHEREUM_SIGNING_KEY)
34+
if (process.env.USER_ETHEREUM_SIGNING_KEY || encodeABI)
2735
return ercContract.methods.approve(spenderAddress, APPROVE_AMOUNT).encodeABI();
2836
await ercContract.methods
2937
.approve(spenderAddress, APPROVE_AMOUNT)
@@ -35,7 +43,7 @@ async function approve(ercAddress, ownerAddress, spenderAddress, tokenType, valu
3543
case TOKEN_TYPE.ERC721:
3644
case TOKEN_TYPE.ERC1155: {
3745
if (!(await ercContract.methods.isApprovedForAll(ownerAddress, spenderAddress).call())) {
38-
if (process.env.USER_ETHEREUM_SIGNING_KEY)
46+
if (process.env.USER_ETHEREUM_SIGNING_KEY || encodeABI)
3947
return ercContract.methods.setApprovalForAll(spenderAddress, true).encodeABI();
4048
await ercContract.methods
4149
.setApprovalForAll(spenderAddress, true)
@@ -191,7 +199,11 @@ async function getERCInfo(ercAddress, ethereumAddress, provider, options) {
191199

192200
await Promise.all(
193201
tokenIdsEvents.map(async Id => {
194-
const amount = await ercContract.methods.balanceOf(ethereumAddress, Id).call();
202+
let amount = await ercContract.methods.balanceOf(ethereumAddress, Id).call();
203+
if (toEth) {
204+
decimals = await getDecimals(ercAddress, TOKEN_TYPE.ERC1155, provider);
205+
amount = fromBaseUnit(amount, decimals);
206+
}
195207
tokenIds.push({ tokenId: Id, amount });
196208
}),
197209
);

‎cli/src/index.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ function printBalances(balances, type) {
144144
for (const compressedPkd in balances) {
145145
const table = new Table({ head: ['ERC Contract Address', `${type} Layer 2 Balance`] });
146146
Object.keys(balances[compressedPkd]).forEach(ercAddress =>
147-
table.push({ [ercAddress]: balances[compressedPkd][ercAddress] }),
147+
table.push({ [ercAddress]: balances[compressedPkd][ercAddress][0] }),
148148
);
149149
console.log(chalk.yellow(`${type} Balances of user ${compressedPkd}`));
150150
console.log(table.toString());

‎cli/src/liquidity-provider.mjs

+2
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ async function startProvider(testEnvironment) {
4343
else throw new Error('Healthcheck failed');
4444
const erc20Address = await nf3.getContractAddress('ERC20Mock');
4545

46+
// Aprove ERC20 contract
4647
await approve(
4748
erc20Address,
4849
nf3.ethereumAddress,
@@ -51,6 +52,7 @@ async function startProvider(testEnvironment) {
5152
APPROVE_AMOUNT,
5253
nf3.web3,
5354
);
55+
5456
// set up a listener to service requests for an instant withdrawal
5557
const emitter = await nf3.getInstantWithdrawalRequestedEmitter();
5658
emitter.on('data', async (withdrawTransactionHash, paidBy, amount) => {

‎doc/lib/nf3.mjs.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -727,7 +727,7 @@ <h1 class="page-title">Source: nf3.mjs</h1>
727727
value of each propery is the number of tokens originating from that contract.
728728
*/
729729
async getLayer2Balances() {
730-
const res = await axios.get(`${this.clientBaseUrl}/commitment/balance`);
730+
const res = await axios.post(`${this.clientBaseUrl}/commitment/balance`);
731731
return res.data.balance;
732732
}
733733

‎nightfall-client/src/routes/commitment.mjs

+11-5
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,20 @@ router.get('/salt', async (req, res, next) => {
3333
router.get('/balance', async (req, res, next) => {
3434
logger.debug('commitment/balance endpoint received GET');
3535
try {
36-
const balance = await getWalletBalance();
36+
const { compressedPkd, ercList } = req.query;
37+
logger.debug(`Details requested with compressedPkd ${compressedPkd} and ercList ${ercList}`);
38+
const balance = await getWalletBalance(compressedPkd, ercList);
3739
res.json({ balance });
3840
} catch (err) {
3941
logger.error(err);
4042
next(err);
4143
}
4244
});
4345

44-
router.post('/balance-details', async (req, res, next) => {
46+
router.get('/balance-details', async (req, res, next) => {
4547
logger.debug('commitment/balance details endpoint received GET');
4648
try {
47-
const { compressedPkd, ercList } = req.body;
49+
const { compressedPkd, ercList } = req.query;
4850
const balance = await getWalletBalanceDetails(compressedPkd, ercList);
4951
res.json({ balance });
5052
} catch (err) {
@@ -56,7 +58,9 @@ router.post('/balance-details', async (req, res, next) => {
5658
router.get('/pending-deposit', async (req, res, next) => {
5759
logger.debug('commitment/pending-deposit endpoint received GET');
5860
try {
59-
const balance = await getWalletPendingDepositBalance();
61+
const { compressedPkd, ercList } = req.query;
62+
logger.debug(`Details requested with compressedPkd ${compressedPkd} and ercList ${ercList}`);
63+
const balance = await getWalletPendingDepositBalance(compressedPkd, ercList);
6064
res.json({ balance });
6165
} catch (err) {
6266
logger.error(err);
@@ -67,7 +71,9 @@ router.get('/pending-deposit', async (req, res, next) => {
6771
router.get('/pending-spent', async (req, res, next) => {
6872
logger.debug('commitment/pending-spent endpoint received GET');
6973
try {
70-
const balance = await getWalletPendingSpentBalance();
74+
const { compressedPkd, ercList } = req.query;
75+
logger.debug(`Details requested with compressedPkd ${compressedPkd} and ercList ${ercList}`);
76+
const balance = await getWalletPendingSpentBalance(compressedPkd, ercList);
7177
res.json({ balance });
7278
} catch (err) {
7379
logger.error(err);

0 commit comments

Comments
 (0)