Skip to content

Commit

Permalink
Fix: allow colony creation with non-colony network tokens
Browse files Browse the repository at this point in the history
Basically, don't presume the token client has the `.locked()`
method available, since the ERC-20 doesn't enforce that.

Just try/catch it, and if not, set the token as 'unlocked'

Fixes: #2264
  • Loading branch information
rdig committed Apr 22, 2024
1 parent cf29884 commit 590e7ca
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
7 changes: 6 additions & 1 deletion amplify/backend/function/createUniqueColony/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,12 @@ exports.handler = async (event) => {
const providerNetwork = await provider.getNetwork();
const chainId = String(providerNetwork.chainId);
const version = await colonyClient.version();
const isTokenLocked = colonyClient.tokenClient.locked();
let isTokenLocked = false;
try {
isTokenLocked = await colonyClient.tokenClient.locked();
} catch (error) {
// token doesn not support the `locked()` method
}

/*
* Create the colony
Expand Down
10 changes: 10 additions & 0 deletions src/redux/sagas/colony/colonyCreate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,12 @@ function* colonyCreate({
},
{
timeout: 30000,
retryLimit: 0,
},
);

console.info({ colonyClient });

/*
* Add a colonyAddress identifier to all pending transactions.
*/
Expand Down Expand Up @@ -335,9 +338,12 @@ function* colonyCreate({
},
{
timeout: 30000,
retryLimit: 0,
},
);

console.info({ oneTxPaymentExtension });

/*
* Generate proofs for setting permissions the the newly deployed OneTxPayment extension
*/
Expand All @@ -348,6 +354,8 @@ function* colonyCreate({
[ColonyRole.Architecture, ColonyRole.Root],
);

console.info({ permissionDomainId, childSkillIndex });

const extensionConfig = supportedExtensionsConfig.find(
(config) => config.extensionId === Extension.OneTxPayment,
);
Expand All @@ -365,6 +373,8 @@ function* colonyCreate({
yield waitForTxResult(setOneTxRoles.channel);
}

console.info('colony should exist right about now', colonyAddress);

/*
* Wait for the colony to exist, then navigate to it.
*/
Expand Down
1 change: 1 addition & 0 deletions src/redux/sagas/transactions/getTransactionPromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ async function getTransactionPromise(
}

console.info('TX DEBUG', {
colonyJSClient: client,
client: client?.clientType || 'unknownContractClient',
methodName,
params,
Expand Down
18 changes: 17 additions & 1 deletion src/redux/sagas/wallet/RetryProvider.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type Block } from '@ethersproject/providers';
import { providers } from 'ethers';
import { providers, utils } from 'ethers';
import { backOff } from 'exponential-backoff';

import { GANACHE_LOCAL_RPC_URL, isDev } from '~constants/index.ts';
Expand Down Expand Up @@ -50,6 +50,22 @@ const classFactory = (
// method is the method name (e.g. getBalance) and params is an
// object with normalized values passed in, depending on the method
perform(method, params) {
// These methods are methods that we call inside try-catches and expect
// to fail sometimes, so don't retry.
const bypassRetryMethods = [
utils.id('locked()').slice(0, 10),
utils.id('nonces(address)').slice(0, 10),
utils.id('getMetatransactionNonce(address)').slice(0, 10),
];
console.info({ method, params });
console.info(params?.transaction?.data?.slice(0, 10));
if (
method === 'call' &&
bypassRetryMethods.includes(params?.transaction?.data?.slice(0, 10))
) {
return super.perform(method, params);
}

return backOff(() => super.perform(method, params), {
retry: this.attemptCheck,
startingDelay: this.delay,
Expand Down

0 comments on commit 590e7ca

Please sign in to comment.