@depay/web3-wallets-evm 14.5.2 → 14.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -59891,6 +59891,91 @@ const getProvider = async (blockchain)=>{
59891
59891
  }
59892
59892
  };
59893
59893
 
59894
+ class Argent {
59895
+
59896
+ constructor ({ address, blockchain }) {
59897
+ this.address = address;
59898
+ this.blockchain = blockchain;
59899
+ }
59900
+
59901
+ async transactionCount() {
59902
+ return 1 // irrelevant as proxy address/relayer actually sending the transaction is not known yet (but needs to be something)
59903
+ }
59904
+ }
59905
+
59906
+ class Safe {
59907
+
59908
+ constructor ({ address, blockchain }) {
59909
+ this.address = address;
59910
+ this.blockchain = blockchain;
59911
+ }
59912
+
59913
+ async transactionCount() {
59914
+ return parseInt((await request({
59915
+ blockchain: this.blockchain,
59916
+ address: this.address,
59917
+ api: [{"inputs":[],"name":"nonce","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}],
59918
+ method: 'nonce',
59919
+ })).toString(), 10)
59920
+ }
59921
+
59922
+ async retrieveTransaction({ blockchain, tx }) {
59923
+ const provider = await getProvider(blockchain);
59924
+ let jsonResult = await fetch(`https://safe-transaction-${blockchain}.safe.global/api/v1/multisig-transactions/${tx}/`)
59925
+ .then((response) => response.json())
59926
+ .catch((error) => { console.error('Error:', error); });
59927
+ if(jsonResult && jsonResult.isExecuted && jsonResult.transactionHash) {
59928
+ return await provider.getTransaction(jsonResult.transactionHash)
59929
+ } else {
59930
+ return undefined
59931
+ }
59932
+ }
59933
+ }
59934
+
59935
+ const isSmartContractWallet = async(blockchain, address)=>{
59936
+ const provider = await getProvider(blockchain);
59937
+ const code = await provider.getCode(address);
59938
+ return (code != '0x')
59939
+ };
59940
+
59941
+ const identifySmartContractWallet = async (blockchain, address)=>{
59942
+ let name;
59943
+ try {
59944
+ name = await request({
59945
+ blockchain,
59946
+ address,
59947
+ api: [{ "constant": true, "inputs": [], "name": "NAME", "outputs": [{ "internalType": "string", "name": "", "type": "string" }], "payable": false, "stateMutability": "view", "type": "function"}],
59948
+ method: 'NAME'
59949
+ });
59950
+ } catch (e) {}
59951
+ if(name == 'Default Callback Handler') { return 'Safe' }
59952
+
59953
+ let executor;
59954
+ try {
59955
+ executor = await request({
59956
+ blockchain,
59957
+ address,
59958
+ api: [{ "constant": true, "inputs": [], "name": "staticCallExecutor", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "payable": false, "stateMutability": "view", "type": "function"}],
59959
+ method: 'staticCallExecutor'
59960
+ });
59961
+ } catch (e2) {}
59962
+ if(executor) { return 'Argent' }
59963
+
59964
+ };
59965
+
59966
+ const getSmartContractWallet = async(blockchain, address)=> {
59967
+ if(!await isSmartContractWallet(blockchain, address)){ return }
59968
+
59969
+ const type = await identifySmartContractWallet(blockchain, address);
59970
+ if(type == 'Safe') {
59971
+ return new Safe({ blockchain, address })
59972
+ } else if(type == 'Argent') {
59973
+ return new Argent({ blockchain, address })
59974
+ } else {
59975
+ throw('Unrecognized smart contract wallet not supported!')
59976
+ }
59977
+ };
59978
+
59894
59979
  const sendTransaction$3 = async ({ transaction, wallet })=> {
59895
59980
  transaction = new Transaction$1(transaction);
59896
59981
  if((await wallet.connectedTo(transaction.blockchain)) == false) {
@@ -59900,7 +59985,8 @@ const sendTransaction$3 = async ({ transaction, wallet })=> {
59900
59985
  throw({ code: 'WRONG_NETWORK' })
59901
59986
  }
59902
59987
  await transaction.prepare({ wallet });
59903
- let transactionCount = await request({ blockchain: transaction.blockchain, method: 'transactionCount', address: transaction.from });
59988
+ const smartContractWallet = await getSmartContractWallet(transaction.blockchain, transaction.from);
59989
+ const transactionCount = smartContractWallet ? await smartContractWallet.transactionCount() : await request({ blockchain: transaction.blockchain, method: 'transactionCount', address: transaction.from });
59904
59990
  transaction.nonce = transactionCount;
59905
59991
  await submit$3({ transaction, wallet }).then(async (tx)=>{
59906
59992
  if (tx) {
@@ -59908,33 +59994,29 @@ const sendTransaction$3 = async ({ transaction, wallet })=> {
59908
59994
  transaction.id = tx;
59909
59995
  transaction.url = blockchain.explorerUrlFor({ transaction });
59910
59996
  if (transaction.sent) transaction.sent(transaction);
59911
- let sentTransaction = await retrieveTransaction$1(tx, transaction.blockchain);
59997
+ let sentTransaction = await retrieveTransaction$1({ blockchain: transaction.blockchain, tx, smartContractWallet });
59998
+ transaction.id = sentTransaction.hash || transaction.id;
59999
+ transaction.url = blockchain.explorerUrlFor({ transaction });
59912
60000
  transaction.nonce = sentTransaction.nonce || transactionCount;
59913
- if(!sentTransaction) {
59914
- transaction._failed = true;
59915
- console.log('Error retrieving transaction');
59916
- if(transaction.failed) transaction.failed(transaction, 'Error retrieving transaction');
59917
- } else {
59918
- sentTransaction.wait(1).then(() => {
59919
- transaction._succeeded = true;
59920
- if (transaction.succeeded) transaction.succeeded(transaction);
59921
- }).catch((error)=>{
59922
- if(error && error.code && error.code == 'TRANSACTION_REPLACED') {
59923
- if(error.replacement && error.replacement.hash && error.receipt && error.receipt.status == 1) {
59924
- transaction.id = error.replacement.hash;
59925
- transaction._succeeded = true;
59926
- if (transaction.succeeded) transaction.succeeded(transaction);
59927
- } else if(error.replacement && error.replacement.hash && error.receipt && error.receipt.status == 0) {
59928
- transaction.id = error.replacement.hash;
59929
- transaction._failed = true;
59930
- if(transaction.failed) transaction.failed(transaction, error);
59931
- }
59932
- } else {
60001
+ sentTransaction.wait(1).then(() => {
60002
+ transaction._succeeded = true;
60003
+ if (transaction.succeeded) transaction.succeeded(transaction);
60004
+ }).catch((error)=>{
60005
+ if(error && error.code && error.code == 'TRANSACTION_REPLACED') {
60006
+ if(error.replacement && error.replacement.hash && error.receipt && error.receipt.status == 1) {
60007
+ transaction.id = error.replacement.hash;
60008
+ transaction._succeeded = true;
60009
+ if (transaction.succeeded) transaction.succeeded(transaction);
60010
+ } else if(error.replacement && error.replacement.hash && error.receipt && error.receipt.status == 0) {
60011
+ transaction.id = error.replacement.hash;
59933
60012
  transaction._failed = true;
59934
- if(transaction.failed) transaction.failed(transaction, error);
60013
+ if(transaction.failed) transaction.failed(transaction, error);
59935
60014
  }
59936
- });
59937
- }
60015
+ } else {
60016
+ transaction._failed = true;
60017
+ if(transaction.failed) transaction.failed(transaction, error);
60018
+ }
60019
+ });
59938
60020
  } else {
59939
60021
  throw('Submitting transaction failed!')
59940
60022
  }
@@ -59942,16 +60024,23 @@ const sendTransaction$3 = async ({ transaction, wallet })=> {
59942
60024
  return transaction
59943
60025
  };
59944
60026
 
59945
- const retrieveTransaction$1 = async (tx, blockchain)=>{
59946
- let sentTransaction;
60027
+ const retrieveTransaction$1 = async ({ blockchain, tx, smartContractWallet })=>{
59947
60028
  const provider = await getProvider(blockchain);
59948
- sentTransaction = await provider.getTransaction(tx);
59949
- const maxRetries = 120;
59950
- let attempt = 1;
59951
- while (attempt <= maxRetries && !sentTransaction) {
59952
- sentTransaction = await provider.getTransaction(tx);
59953
- await (new Promise((resolve)=>setTimeout(resolve, 5000)));
59954
- attempt++;
60029
+ let retrieve = async()=>{
60030
+ try {
60031
+ if(smartContractWallet && smartContractWallet.retrieveTransaction) {
60032
+ return await smartContractWallet.retrieveTransaction({ blockchain, tx })
60033
+ } else {
60034
+ return await provider.getTransaction(tx)
60035
+ }
60036
+ } catch (e) {}
60037
+ };
60038
+
60039
+ let sentTransaction;
60040
+ sentTransaction = await retrieve();
60041
+ while (!sentTransaction) {
60042
+ await (new Promise((resolve)=>setTimeout(resolve, 3000)));
60043
+ sentTransaction = await retrieve();
59955
60044
  }
59956
60045
  return sentTransaction
59957
60046
  };
@@ -59971,15 +60060,6 @@ const submitContractInteraction$2 = async ({ transaction, wallet })=>{
59971
60060
  const data = await transaction.getData();
59972
60061
  const value = transaction.value ? ethers.utils.hexlify(ethers.BigNumber.from(transaction.value)) : undefined;
59973
60062
  const nonce = ethers.utils.hexlify(transaction.nonce);
59974
- console.log({
59975
- from: transaction.from,
59976
- to: transaction.to,
59977
- value,
59978
- data,
59979
- gas: gas.toHexString(),
59980
- gasPrice: gasPrice.toHexString(),
59981
- nonce,
59982
- });
59983
60063
  return wallet.connector.sendTransaction({
59984
60064
  from: transaction.from,
59985
60065
  to: transaction.to,
@@ -59997,15 +60077,6 @@ const submitSimpleTransfer$3 = async ({ transaction, wallet })=>{
59997
60077
  const gas = await estimate(transaction);
59998
60078
  const value = ethers.utils.hexlify(ethers.BigNumber.from(transaction.value));
59999
60079
  const nonce = ethers.utils.hexlify(transaction.nonce);
60000
- console.log({
60001
- from: transaction.from,
60002
- to: transaction.to,
60003
- value,
60004
- data: '0x',
60005
- gas: gas.toHexString(),
60006
- gasPrice: gasPrice.toHexString(),
60007
- nonce,
60008
- });
60009
60080
  return wallet.connector.sendTransaction({
60010
60081
  from: transaction.from,
60011
60082
  to: transaction.to,
package/dist/esm/index.js CHANGED
@@ -985,6 +985,91 @@ class Trust extends WindowEthereum {
985
985
  static __initStatic2() {this.isAvailable = ()=>{ return (_optionalChain$3([window, 'optionalAccess', _5 => _5.ethereum, 'optionalAccess', _6 => _6.isTrust]) || _optionalChain$3([window, 'optionalAccess', _7 => _7.ethereum, 'optionalAccess', _8 => _8.isTrustWallet])) };}
986
986
  } Trust.__initStatic(); Trust.__initStatic2();
987
987
 
988
+ class Argent {
989
+
990
+ constructor ({ address, blockchain }) {
991
+ this.address = address;
992
+ this.blockchain = blockchain;
993
+ }
994
+
995
+ async transactionCount() {
996
+ return 1 // irrelevant as proxy address/relayer actually sending the transaction is not known yet (but needs to be something)
997
+ }
998
+ }
999
+
1000
+ class Safe {
1001
+
1002
+ constructor ({ address, blockchain }) {
1003
+ this.address = address;
1004
+ this.blockchain = blockchain;
1005
+ }
1006
+
1007
+ async transactionCount() {
1008
+ return parseInt((await request$1({
1009
+ blockchain: this.blockchain,
1010
+ address: this.address,
1011
+ api: [{"inputs":[],"name":"nonce","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}],
1012
+ method: 'nonce',
1013
+ })).toString(), 10)
1014
+ }
1015
+
1016
+ async retrieveTransaction({ blockchain, tx }) {
1017
+ const provider = await getProvider(blockchain);
1018
+ let jsonResult = await fetch(`https://safe-transaction-${blockchain}.safe.global/api/v1/multisig-transactions/${tx}/`)
1019
+ .then((response) => response.json())
1020
+ .catch((error) => { console.error('Error:', error); });
1021
+ if(jsonResult && jsonResult.isExecuted && jsonResult.transactionHash) {
1022
+ return await provider.getTransaction(jsonResult.transactionHash)
1023
+ } else {
1024
+ return undefined
1025
+ }
1026
+ }
1027
+ }
1028
+
1029
+ const isSmartContractWallet = async(blockchain, address)=>{
1030
+ const provider = await getProvider(blockchain);
1031
+ const code = await provider.getCode(address);
1032
+ return (code != '0x')
1033
+ };
1034
+
1035
+ const identifySmartContractWallet = async (blockchain, address)=>{
1036
+ let name;
1037
+ try {
1038
+ name = await request$1({
1039
+ blockchain,
1040
+ address,
1041
+ api: [{ "constant": true, "inputs": [], "name": "NAME", "outputs": [{ "internalType": "string", "name": "", "type": "string" }], "payable": false, "stateMutability": "view", "type": "function"}],
1042
+ method: 'NAME'
1043
+ });
1044
+ } catch (e) {}
1045
+ if(name == 'Default Callback Handler') { return 'Safe' }
1046
+
1047
+ let executor;
1048
+ try {
1049
+ executor = await request$1({
1050
+ blockchain,
1051
+ address,
1052
+ api: [{ "constant": true, "inputs": [], "name": "staticCallExecutor", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "payable": false, "stateMutability": "view", "type": "function"}],
1053
+ method: 'staticCallExecutor'
1054
+ });
1055
+ } catch (e2) {}
1056
+ if(executor) { return 'Argent' }
1057
+
1058
+ };
1059
+
1060
+ const getSmartContractWallet = async(blockchain, address)=> {
1061
+ if(!await isSmartContractWallet(blockchain, address)){ return }
1062
+
1063
+ const type = await identifySmartContractWallet(blockchain, address);
1064
+ if(type == 'Safe') {
1065
+ return new Safe({ blockchain, address })
1066
+ } else if(type == 'Argent') {
1067
+ return new Argent({ blockchain, address })
1068
+ } else {
1069
+ throw('Unrecognized smart contract wallet not supported!')
1070
+ }
1071
+ };
1072
+
988
1073
  const sendTransaction$2 = async ({ transaction, wallet })=> {
989
1074
  transaction = new Transaction(transaction);
990
1075
  if((await wallet.connectedTo(transaction.blockchain)) == false) {
@@ -994,7 +1079,8 @@ const sendTransaction$2 = async ({ transaction, wallet })=> {
994
1079
  throw({ code: 'WRONG_NETWORK' })
995
1080
  }
996
1081
  await transaction.prepare({ wallet });
997
- let transactionCount = await request$1({ blockchain: transaction.blockchain, method: 'transactionCount', address: transaction.from });
1082
+ const smartContractWallet = await getSmartContractWallet(transaction.blockchain, transaction.from);
1083
+ const transactionCount = smartContractWallet ? await smartContractWallet.transactionCount() : await request$1({ blockchain: transaction.blockchain, method: 'transactionCount', address: transaction.from });
998
1084
  transaction.nonce = transactionCount;
999
1085
  await submit$2({ transaction, wallet }).then(async (tx)=>{
1000
1086
  if (tx) {
@@ -1002,33 +1088,29 @@ const sendTransaction$2 = async ({ transaction, wallet })=> {
1002
1088
  transaction.id = tx;
1003
1089
  transaction.url = blockchain.explorerUrlFor({ transaction });
1004
1090
  if (transaction.sent) transaction.sent(transaction);
1005
- let sentTransaction = await retrieveTransaction$1(tx, transaction.blockchain);
1091
+ let sentTransaction = await retrieveTransaction$1({ blockchain: transaction.blockchain, tx, smartContractWallet });
1092
+ transaction.id = sentTransaction.hash || transaction.id;
1093
+ transaction.url = blockchain.explorerUrlFor({ transaction });
1006
1094
  transaction.nonce = sentTransaction.nonce || transactionCount;
1007
- if(!sentTransaction) {
1008
- transaction._failed = true;
1009
- console.log('Error retrieving transaction');
1010
- if(transaction.failed) transaction.failed(transaction, 'Error retrieving transaction');
1011
- } else {
1012
- sentTransaction.wait(1).then(() => {
1013
- transaction._succeeded = true;
1014
- if (transaction.succeeded) transaction.succeeded(transaction);
1015
- }).catch((error)=>{
1016
- if(error && error.code && error.code == 'TRANSACTION_REPLACED') {
1017
- if(error.replacement && error.replacement.hash && error.receipt && error.receipt.status == 1) {
1018
- transaction.id = error.replacement.hash;
1019
- transaction._succeeded = true;
1020
- if (transaction.succeeded) transaction.succeeded(transaction);
1021
- } else if(error.replacement && error.replacement.hash && error.receipt && error.receipt.status == 0) {
1022
- transaction.id = error.replacement.hash;
1023
- transaction._failed = true;
1024
- if(transaction.failed) transaction.failed(transaction, error);
1025
- }
1026
- } else {
1095
+ sentTransaction.wait(1).then(() => {
1096
+ transaction._succeeded = true;
1097
+ if (transaction.succeeded) transaction.succeeded(transaction);
1098
+ }).catch((error)=>{
1099
+ if(error && error.code && error.code == 'TRANSACTION_REPLACED') {
1100
+ if(error.replacement && error.replacement.hash && error.receipt && error.receipt.status == 1) {
1101
+ transaction.id = error.replacement.hash;
1102
+ transaction._succeeded = true;
1103
+ if (transaction.succeeded) transaction.succeeded(transaction);
1104
+ } else if(error.replacement && error.replacement.hash && error.receipt && error.receipt.status == 0) {
1105
+ transaction.id = error.replacement.hash;
1027
1106
  transaction._failed = true;
1028
- if(transaction.failed) transaction.failed(transaction, error);
1107
+ if(transaction.failed) transaction.failed(transaction, error);
1029
1108
  }
1030
- });
1031
- }
1109
+ } else {
1110
+ transaction._failed = true;
1111
+ if(transaction.failed) transaction.failed(transaction, error);
1112
+ }
1113
+ });
1032
1114
  } else {
1033
1115
  throw('Submitting transaction failed!')
1034
1116
  }
@@ -1036,16 +1118,23 @@ const sendTransaction$2 = async ({ transaction, wallet })=> {
1036
1118
  return transaction
1037
1119
  };
1038
1120
 
1039
- const retrieveTransaction$1 = async (tx, blockchain)=>{
1040
- let sentTransaction;
1121
+ const retrieveTransaction$1 = async ({ blockchain, tx, smartContractWallet })=>{
1041
1122
  const provider = await getProvider(blockchain);
1042
- sentTransaction = await provider.getTransaction(tx);
1043
- const maxRetries = 120;
1044
- let attempt = 1;
1045
- while (attempt <= maxRetries && !sentTransaction) {
1046
- sentTransaction = await provider.getTransaction(tx);
1047
- await (new Promise((resolve)=>setTimeout(resolve, 5000)));
1048
- attempt++;
1123
+ let retrieve = async()=>{
1124
+ try {
1125
+ if(smartContractWallet && smartContractWallet.retrieveTransaction) {
1126
+ return await smartContractWallet.retrieveTransaction({ blockchain, tx })
1127
+ } else {
1128
+ return await provider.getTransaction(tx)
1129
+ }
1130
+ } catch (e) {}
1131
+ };
1132
+
1133
+ let sentTransaction;
1134
+ sentTransaction = await retrieve();
1135
+ while (!sentTransaction) {
1136
+ await (new Promise((resolve)=>setTimeout(resolve, 3000)));
1137
+ sentTransaction = await retrieve();
1049
1138
  }
1050
1139
  return sentTransaction
1051
1140
  };
@@ -1065,15 +1154,6 @@ const submitContractInteraction$2 = async ({ transaction, wallet })=>{
1065
1154
  const data = await transaction.getData();
1066
1155
  const value = transaction.value ? ethers.utils.hexlify(ethers.BigNumber.from(transaction.value)) : undefined;
1067
1156
  const nonce = ethers.utils.hexlify(transaction.nonce);
1068
- console.log({
1069
- from: transaction.from,
1070
- to: transaction.to,
1071
- value,
1072
- data,
1073
- gas: gas.toHexString(),
1074
- gasPrice: gasPrice.toHexString(),
1075
- nonce,
1076
- });
1077
1157
  return wallet.connector.sendTransaction({
1078
1158
  from: transaction.from,
1079
1159
  to: transaction.to,
@@ -1091,15 +1171,6 @@ const submitSimpleTransfer$2 = async ({ transaction, wallet })=>{
1091
1171
  const gas = await estimate(transaction);
1092
1172
  const value = ethers.utils.hexlify(ethers.BigNumber.from(transaction.value));
1093
1173
  const nonce = ethers.utils.hexlify(transaction.nonce);
1094
- console.log({
1095
- from: transaction.from,
1096
- to: transaction.to,
1097
- value,
1098
- data: '0x',
1099
- gas: gas.toHexString(),
1100
- gasPrice: gasPrice.toHexString(),
1101
- nonce,
1102
- });
1103
1174
  return wallet.connector.sendTransaction({
1104
1175
  from: transaction.from,
1105
1176
  to: transaction.to,
@@ -59889,6 +59889,91 @@
59889
59889
  }
59890
59890
  };
59891
59891
 
59892
+ class Argent {
59893
+
59894
+ constructor ({ address, blockchain }) {
59895
+ this.address = address;
59896
+ this.blockchain = blockchain;
59897
+ }
59898
+
59899
+ async transactionCount() {
59900
+ return 1 // irrelevant as proxy address/relayer actually sending the transaction is not known yet (but needs to be something)
59901
+ }
59902
+ }
59903
+
59904
+ class Safe {
59905
+
59906
+ constructor ({ address, blockchain }) {
59907
+ this.address = address;
59908
+ this.blockchain = blockchain;
59909
+ }
59910
+
59911
+ async transactionCount() {
59912
+ return parseInt((await request({
59913
+ blockchain: this.blockchain,
59914
+ address: this.address,
59915
+ api: [{"inputs":[],"name":"nonce","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}],
59916
+ method: 'nonce',
59917
+ })).toString(), 10)
59918
+ }
59919
+
59920
+ async retrieveTransaction({ blockchain, tx }) {
59921
+ const provider = await getProvider(blockchain);
59922
+ let jsonResult = await fetch(`https://safe-transaction-${blockchain}.safe.global/api/v1/multisig-transactions/${tx}/`)
59923
+ .then((response) => response.json())
59924
+ .catch((error) => { console.error('Error:', error); });
59925
+ if(jsonResult && jsonResult.isExecuted && jsonResult.transactionHash) {
59926
+ return await provider.getTransaction(jsonResult.transactionHash)
59927
+ } else {
59928
+ return undefined
59929
+ }
59930
+ }
59931
+ }
59932
+
59933
+ const isSmartContractWallet = async(blockchain, address)=>{
59934
+ const provider = await getProvider(blockchain);
59935
+ const code = await provider.getCode(address);
59936
+ return (code != '0x')
59937
+ };
59938
+
59939
+ const identifySmartContractWallet = async (blockchain, address)=>{
59940
+ let name;
59941
+ try {
59942
+ name = await request({
59943
+ blockchain,
59944
+ address,
59945
+ api: [{ "constant": true, "inputs": [], "name": "NAME", "outputs": [{ "internalType": "string", "name": "", "type": "string" }], "payable": false, "stateMutability": "view", "type": "function"}],
59946
+ method: 'NAME'
59947
+ });
59948
+ } catch (e) {}
59949
+ if(name == 'Default Callback Handler') { return 'Safe' }
59950
+
59951
+ let executor;
59952
+ try {
59953
+ executor = await request({
59954
+ blockchain,
59955
+ address,
59956
+ api: [{ "constant": true, "inputs": [], "name": "staticCallExecutor", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "payable": false, "stateMutability": "view", "type": "function"}],
59957
+ method: 'staticCallExecutor'
59958
+ });
59959
+ } catch (e2) {}
59960
+ if(executor) { return 'Argent' }
59961
+
59962
+ };
59963
+
59964
+ const getSmartContractWallet = async(blockchain, address)=> {
59965
+ if(!await isSmartContractWallet(blockchain, address)){ return }
59966
+
59967
+ const type = await identifySmartContractWallet(blockchain, address);
59968
+ if(type == 'Safe') {
59969
+ return new Safe({ blockchain, address })
59970
+ } else if(type == 'Argent') {
59971
+ return new Argent({ blockchain, address })
59972
+ } else {
59973
+ throw('Unrecognized smart contract wallet not supported!')
59974
+ }
59975
+ };
59976
+
59892
59977
  const sendTransaction$3 = async ({ transaction, wallet })=> {
59893
59978
  transaction = new Transaction$1(transaction);
59894
59979
  if((await wallet.connectedTo(transaction.blockchain)) == false) {
@@ -59898,7 +59983,8 @@
59898
59983
  throw({ code: 'WRONG_NETWORK' })
59899
59984
  }
59900
59985
  await transaction.prepare({ wallet });
59901
- let transactionCount = await request({ blockchain: transaction.blockchain, method: 'transactionCount', address: transaction.from });
59986
+ const smartContractWallet = await getSmartContractWallet(transaction.blockchain, transaction.from);
59987
+ const transactionCount = smartContractWallet ? await smartContractWallet.transactionCount() : await request({ blockchain: transaction.blockchain, method: 'transactionCount', address: transaction.from });
59902
59988
  transaction.nonce = transactionCount;
59903
59989
  await submit$3({ transaction, wallet }).then(async (tx)=>{
59904
59990
  if (tx) {
@@ -59906,33 +59992,29 @@
59906
59992
  transaction.id = tx;
59907
59993
  transaction.url = blockchain.explorerUrlFor({ transaction });
59908
59994
  if (transaction.sent) transaction.sent(transaction);
59909
- let sentTransaction = await retrieveTransaction$1(tx, transaction.blockchain);
59995
+ let sentTransaction = await retrieveTransaction$1({ blockchain: transaction.blockchain, tx, smartContractWallet });
59996
+ transaction.id = sentTransaction.hash || transaction.id;
59997
+ transaction.url = blockchain.explorerUrlFor({ transaction });
59910
59998
  transaction.nonce = sentTransaction.nonce || transactionCount;
59911
- if(!sentTransaction) {
59912
- transaction._failed = true;
59913
- console.log('Error retrieving transaction');
59914
- if(transaction.failed) transaction.failed(transaction, 'Error retrieving transaction');
59915
- } else {
59916
- sentTransaction.wait(1).then(() => {
59917
- transaction._succeeded = true;
59918
- if (transaction.succeeded) transaction.succeeded(transaction);
59919
- }).catch((error)=>{
59920
- if(error && error.code && error.code == 'TRANSACTION_REPLACED') {
59921
- if(error.replacement && error.replacement.hash && error.receipt && error.receipt.status == 1) {
59922
- transaction.id = error.replacement.hash;
59923
- transaction._succeeded = true;
59924
- if (transaction.succeeded) transaction.succeeded(transaction);
59925
- } else if(error.replacement && error.replacement.hash && error.receipt && error.receipt.status == 0) {
59926
- transaction.id = error.replacement.hash;
59927
- transaction._failed = true;
59928
- if(transaction.failed) transaction.failed(transaction, error);
59929
- }
59930
- } else {
59999
+ sentTransaction.wait(1).then(() => {
60000
+ transaction._succeeded = true;
60001
+ if (transaction.succeeded) transaction.succeeded(transaction);
60002
+ }).catch((error)=>{
60003
+ if(error && error.code && error.code == 'TRANSACTION_REPLACED') {
60004
+ if(error.replacement && error.replacement.hash && error.receipt && error.receipt.status == 1) {
60005
+ transaction.id = error.replacement.hash;
60006
+ transaction._succeeded = true;
60007
+ if (transaction.succeeded) transaction.succeeded(transaction);
60008
+ } else if(error.replacement && error.replacement.hash && error.receipt && error.receipt.status == 0) {
60009
+ transaction.id = error.replacement.hash;
59931
60010
  transaction._failed = true;
59932
- if(transaction.failed) transaction.failed(transaction, error);
60011
+ if(transaction.failed) transaction.failed(transaction, error);
59933
60012
  }
59934
- });
59935
- }
60013
+ } else {
60014
+ transaction._failed = true;
60015
+ if(transaction.failed) transaction.failed(transaction, error);
60016
+ }
60017
+ });
59936
60018
  } else {
59937
60019
  throw('Submitting transaction failed!')
59938
60020
  }
@@ -59940,16 +60022,23 @@
59940
60022
  return transaction
59941
60023
  };
59942
60024
 
59943
- const retrieveTransaction$1 = async (tx, blockchain)=>{
59944
- let sentTransaction;
60025
+ const retrieveTransaction$1 = async ({ blockchain, tx, smartContractWallet })=>{
59945
60026
  const provider = await getProvider(blockchain);
59946
- sentTransaction = await provider.getTransaction(tx);
59947
- const maxRetries = 120;
59948
- let attempt = 1;
59949
- while (attempt <= maxRetries && !sentTransaction) {
59950
- sentTransaction = await provider.getTransaction(tx);
59951
- await (new Promise((resolve)=>setTimeout(resolve, 5000)));
59952
- attempt++;
60027
+ let retrieve = async()=>{
60028
+ try {
60029
+ if(smartContractWallet && smartContractWallet.retrieveTransaction) {
60030
+ return await smartContractWallet.retrieveTransaction({ blockchain, tx })
60031
+ } else {
60032
+ return await provider.getTransaction(tx)
60033
+ }
60034
+ } catch (e) {}
60035
+ };
60036
+
60037
+ let sentTransaction;
60038
+ sentTransaction = await retrieve();
60039
+ while (!sentTransaction) {
60040
+ await (new Promise((resolve)=>setTimeout(resolve, 3000)));
60041
+ sentTransaction = await retrieve();
59953
60042
  }
59954
60043
  return sentTransaction
59955
60044
  };
@@ -59969,15 +60058,6 @@
59969
60058
  const data = await transaction.getData();
59970
60059
  const value = transaction.value ? ethers.ethers.utils.hexlify(ethers.ethers.BigNumber.from(transaction.value)) : undefined;
59971
60060
  const nonce = ethers.ethers.utils.hexlify(transaction.nonce);
59972
- console.log({
59973
- from: transaction.from,
59974
- to: transaction.to,
59975
- value,
59976
- data,
59977
- gas: gas.toHexString(),
59978
- gasPrice: gasPrice.toHexString(),
59979
- nonce,
59980
- });
59981
60061
  return wallet.connector.sendTransaction({
59982
60062
  from: transaction.from,
59983
60063
  to: transaction.to,
@@ -59995,15 +60075,6 @@
59995
60075
  const gas = await estimate(transaction);
59996
60076
  const value = ethers.ethers.utils.hexlify(ethers.ethers.BigNumber.from(transaction.value));
59997
60077
  const nonce = ethers.ethers.utils.hexlify(transaction.nonce);
59998
- console.log({
59999
- from: transaction.from,
60000
- to: transaction.to,
60001
- value,
60002
- data: '0x',
60003
- gas: gas.toHexString(),
60004
- gasPrice: gasPrice.toHexString(),
60005
- nonce,
60006
- });
60007
60078
  return wallet.connector.sendTransaction({
60008
60079
  from: transaction.from,
60009
60080
  to: transaction.to,
package/dist/umd/index.js CHANGED
@@ -982,6 +982,91 @@
982
982
  static __initStatic2() {this.isAvailable = ()=>{ return (_optionalChain$3([window, 'optionalAccess', _5 => _5.ethereum, 'optionalAccess', _6 => _6.isTrust]) || _optionalChain$3([window, 'optionalAccess', _7 => _7.ethereum, 'optionalAccess', _8 => _8.isTrustWallet])) };}
983
983
  } Trust.__initStatic(); Trust.__initStatic2();
984
984
 
985
+ class Argent {
986
+
987
+ constructor ({ address, blockchain }) {
988
+ this.address = address;
989
+ this.blockchain = blockchain;
990
+ }
991
+
992
+ async transactionCount() {
993
+ return 1 // irrelevant as proxy address/relayer actually sending the transaction is not known yet (but needs to be something)
994
+ }
995
+ }
996
+
997
+ class Safe {
998
+
999
+ constructor ({ address, blockchain }) {
1000
+ this.address = address;
1001
+ this.blockchain = blockchain;
1002
+ }
1003
+
1004
+ async transactionCount() {
1005
+ return parseInt((await web3Client.request({
1006
+ blockchain: this.blockchain,
1007
+ address: this.address,
1008
+ api: [{"inputs":[],"name":"nonce","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"}],
1009
+ method: 'nonce',
1010
+ })).toString(), 10)
1011
+ }
1012
+
1013
+ async retrieveTransaction({ blockchain, tx }) {
1014
+ const provider = await web3Client.getProvider(blockchain);
1015
+ let jsonResult = await fetch(`https://safe-transaction-${blockchain}.safe.global/api/v1/multisig-transactions/${tx}/`)
1016
+ .then((response) => response.json())
1017
+ .catch((error) => { console.error('Error:', error); });
1018
+ if(jsonResult && jsonResult.isExecuted && jsonResult.transactionHash) {
1019
+ return await provider.getTransaction(jsonResult.transactionHash)
1020
+ } else {
1021
+ return undefined
1022
+ }
1023
+ }
1024
+ }
1025
+
1026
+ const isSmartContractWallet = async(blockchain, address)=>{
1027
+ const provider = await web3Client.getProvider(blockchain);
1028
+ const code = await provider.getCode(address);
1029
+ return (code != '0x')
1030
+ };
1031
+
1032
+ const identifySmartContractWallet = async (blockchain, address)=>{
1033
+ let name;
1034
+ try {
1035
+ name = await web3Client.request({
1036
+ blockchain,
1037
+ address,
1038
+ api: [{ "constant": true, "inputs": [], "name": "NAME", "outputs": [{ "internalType": "string", "name": "", "type": "string" }], "payable": false, "stateMutability": "view", "type": "function"}],
1039
+ method: 'NAME'
1040
+ });
1041
+ } catch (e) {}
1042
+ if(name == 'Default Callback Handler') { return 'Safe' }
1043
+
1044
+ let executor;
1045
+ try {
1046
+ executor = await web3Client.request({
1047
+ blockchain,
1048
+ address,
1049
+ api: [{ "constant": true, "inputs": [], "name": "staticCallExecutor", "outputs": [{ "internalType": "address", "name": "", "type": "address" }], "payable": false, "stateMutability": "view", "type": "function"}],
1050
+ method: 'staticCallExecutor'
1051
+ });
1052
+ } catch (e2) {}
1053
+ if(executor) { return 'Argent' }
1054
+
1055
+ };
1056
+
1057
+ const getSmartContractWallet = async(blockchain, address)=> {
1058
+ if(!await isSmartContractWallet(blockchain, address)){ return }
1059
+
1060
+ const type = await identifySmartContractWallet(blockchain, address);
1061
+ if(type == 'Safe') {
1062
+ return new Safe({ blockchain, address })
1063
+ } else if(type == 'Argent') {
1064
+ return new Argent({ blockchain, address })
1065
+ } else {
1066
+ throw('Unrecognized smart contract wallet not supported!')
1067
+ }
1068
+ };
1069
+
985
1070
  const sendTransaction$2 = async ({ transaction, wallet })=> {
986
1071
  transaction = new Transaction(transaction);
987
1072
  if((await wallet.connectedTo(transaction.blockchain)) == false) {
@@ -991,7 +1076,8 @@
991
1076
  throw({ code: 'WRONG_NETWORK' })
992
1077
  }
993
1078
  await transaction.prepare({ wallet });
994
- let transactionCount = await web3Client.request({ blockchain: transaction.blockchain, method: 'transactionCount', address: transaction.from });
1079
+ const smartContractWallet = await getSmartContractWallet(transaction.blockchain, transaction.from);
1080
+ const transactionCount = smartContractWallet ? await smartContractWallet.transactionCount() : await web3Client.request({ blockchain: transaction.blockchain, method: 'transactionCount', address: transaction.from });
995
1081
  transaction.nonce = transactionCount;
996
1082
  await submit$2({ transaction, wallet }).then(async (tx)=>{
997
1083
  if (tx) {
@@ -999,33 +1085,29 @@
999
1085
  transaction.id = tx;
1000
1086
  transaction.url = blockchain.explorerUrlFor({ transaction });
1001
1087
  if (transaction.sent) transaction.sent(transaction);
1002
- let sentTransaction = await retrieveTransaction$1(tx, transaction.blockchain);
1088
+ let sentTransaction = await retrieveTransaction$1({ blockchain: transaction.blockchain, tx, smartContractWallet });
1089
+ transaction.id = sentTransaction.hash || transaction.id;
1090
+ transaction.url = blockchain.explorerUrlFor({ transaction });
1003
1091
  transaction.nonce = sentTransaction.nonce || transactionCount;
1004
- if(!sentTransaction) {
1005
- transaction._failed = true;
1006
- console.log('Error retrieving transaction');
1007
- if(transaction.failed) transaction.failed(transaction, 'Error retrieving transaction');
1008
- } else {
1009
- sentTransaction.wait(1).then(() => {
1010
- transaction._succeeded = true;
1011
- if (transaction.succeeded) transaction.succeeded(transaction);
1012
- }).catch((error)=>{
1013
- if(error && error.code && error.code == 'TRANSACTION_REPLACED') {
1014
- if(error.replacement && error.replacement.hash && error.receipt && error.receipt.status == 1) {
1015
- transaction.id = error.replacement.hash;
1016
- transaction._succeeded = true;
1017
- if (transaction.succeeded) transaction.succeeded(transaction);
1018
- } else if(error.replacement && error.replacement.hash && error.receipt && error.receipt.status == 0) {
1019
- transaction.id = error.replacement.hash;
1020
- transaction._failed = true;
1021
- if(transaction.failed) transaction.failed(transaction, error);
1022
- }
1023
- } else {
1092
+ sentTransaction.wait(1).then(() => {
1093
+ transaction._succeeded = true;
1094
+ if (transaction.succeeded) transaction.succeeded(transaction);
1095
+ }).catch((error)=>{
1096
+ if(error && error.code && error.code == 'TRANSACTION_REPLACED') {
1097
+ if(error.replacement && error.replacement.hash && error.receipt && error.receipt.status == 1) {
1098
+ transaction.id = error.replacement.hash;
1099
+ transaction._succeeded = true;
1100
+ if (transaction.succeeded) transaction.succeeded(transaction);
1101
+ } else if(error.replacement && error.replacement.hash && error.receipt && error.receipt.status == 0) {
1102
+ transaction.id = error.replacement.hash;
1024
1103
  transaction._failed = true;
1025
- if(transaction.failed) transaction.failed(transaction, error);
1104
+ if(transaction.failed) transaction.failed(transaction, error);
1026
1105
  }
1027
- });
1028
- }
1106
+ } else {
1107
+ transaction._failed = true;
1108
+ if(transaction.failed) transaction.failed(transaction, error);
1109
+ }
1110
+ });
1029
1111
  } else {
1030
1112
  throw('Submitting transaction failed!')
1031
1113
  }
@@ -1033,16 +1115,23 @@
1033
1115
  return transaction
1034
1116
  };
1035
1117
 
1036
- const retrieveTransaction$1 = async (tx, blockchain)=>{
1037
- let sentTransaction;
1118
+ const retrieveTransaction$1 = async ({ blockchain, tx, smartContractWallet })=>{
1038
1119
  const provider = await web3Client.getProvider(blockchain);
1039
- sentTransaction = await provider.getTransaction(tx);
1040
- const maxRetries = 120;
1041
- let attempt = 1;
1042
- while (attempt <= maxRetries && !sentTransaction) {
1043
- sentTransaction = await provider.getTransaction(tx);
1044
- await (new Promise((resolve)=>setTimeout(resolve, 5000)));
1045
- attempt++;
1120
+ let retrieve = async()=>{
1121
+ try {
1122
+ if(smartContractWallet && smartContractWallet.retrieveTransaction) {
1123
+ return await smartContractWallet.retrieveTransaction({ blockchain, tx })
1124
+ } else {
1125
+ return await provider.getTransaction(tx)
1126
+ }
1127
+ } catch (e) {}
1128
+ };
1129
+
1130
+ let sentTransaction;
1131
+ sentTransaction = await retrieve();
1132
+ while (!sentTransaction) {
1133
+ await (new Promise((resolve)=>setTimeout(resolve, 3000)));
1134
+ sentTransaction = await retrieve();
1046
1135
  }
1047
1136
  return sentTransaction
1048
1137
  };
@@ -1062,15 +1151,6 @@
1062
1151
  const data = await transaction.getData();
1063
1152
  const value = transaction.value ? ethers.ethers.utils.hexlify(ethers.ethers.BigNumber.from(transaction.value)) : undefined;
1064
1153
  const nonce = ethers.ethers.utils.hexlify(transaction.nonce);
1065
- console.log({
1066
- from: transaction.from,
1067
- to: transaction.to,
1068
- value,
1069
- data,
1070
- gas: gas.toHexString(),
1071
- gasPrice: gasPrice.toHexString(),
1072
- nonce,
1073
- });
1074
1154
  return wallet.connector.sendTransaction({
1075
1155
  from: transaction.from,
1076
1156
  to: transaction.to,
@@ -1088,15 +1168,6 @@
1088
1168
  const gas = await web3Client.estimate(transaction);
1089
1169
  const value = ethers.ethers.utils.hexlify(ethers.ethers.BigNumber.from(transaction.value));
1090
1170
  const nonce = ethers.ethers.utils.hexlify(transaction.nonce);
1091
- console.log({
1092
- from: transaction.from,
1093
- to: transaction.to,
1094
- value,
1095
- data: '0x',
1096
- gas: gas.toHexString(),
1097
- gasPrice: gasPrice.toHexString(),
1098
- nonce,
1099
- });
1100
1171
  return wallet.connector.sendTransaction({
1101
1172
  from: transaction.from,
1102
1173
  to: transaction.to,
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@depay/web3-wallets-evm",
3
3
  "moduleName": "Web3Wallets",
4
- "version": "14.5.2",
4
+ "version": "14.6.0",
5
5
  "description": "One-Stop-Shop JavaScript library to integrate various web3 crypto wallets and multiple blockchains at once with a single interface.",
6
6
  "main": "dist/umd/index.evm.js",
7
7
  "module": "dist/esm/index.evm.js",