@fairmint/safe-js
Advanced tools
Comparing version 1.4.5 to 1.4.6
{ | ||
"name": "@fairmint/safe-js", | ||
"version": "1.4.5", | ||
"version": "1.4.6", | ||
"description": "Safe javascript library.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -28,7 +28,11 @@ const abi = require("@fairmint/cafe-abi/abi.json"); | ||
if (currencyAddress && currencyAddress !== constants.ZERO_ADDRESS) { | ||
this.currency = contract.at(this.provider, abi.erc20, currencyAddress) | ||
this.currency = contract.at(this.provider, abi.erc20, currencyAddress); | ||
} else { | ||
throw new Error('No currency contract address') | ||
throw new Error("No currency contract address"); | ||
} | ||
this.whitelist = contract.at(this.provider, abi.whitelist, whitelistAddress); | ||
this.whitelist = contract.at( | ||
this.provider, | ||
abi.whitelist, | ||
whitelistAddress | ||
); | ||
@@ -223,7 +227,8 @@ const [ | ||
this.currency | ||
? this.currency.balanceOf(accountAddress) | ||
? this.currency.balanceOf(accountAddress).then(contract.converter) | ||
: undefined, | ||
this.currency | ||
? this.currency | ||
.allowance(accountAddress, this.dat.address) | ||
.allowance(accountAddress, this.dat.address) | ||
.then(contract.converter) | ||
: undefined, | ||
@@ -239,2 +244,3 @@ ]); | ||
.authorizedWalletToUserId(accountAddress) | ||
.then(contract.converter); | ||
account.whitelist = { | ||
@@ -249,3 +255,5 @@ userId, | ||
endIndex, | ||
} = await this.whitelist.getAuthorizedUserIdInfo(userId); | ||
} = await this.whitelist | ||
.getAuthorizedUserIdInfo(userId) | ||
.then(contract.converter); | ||
account.whitelist.jurisdictionId = jurisdictionId; | ||
@@ -280,3 +288,5 @@ account.whitelist.totalTokensLocked = totalTokensLocked; | ||
async refreshAccountInfo(accountAddress) { | ||
this.data.account = await this.getAccountInfo(accountAddress); | ||
this.data.account = await this.getAccountInfo(accountAddress).then( | ||
contract.converter | ||
); | ||
} | ||
@@ -307,3 +317,5 @@ | ||
if (this.currency) { | ||
balance = await this.currency.balanceOf(accountAddress); | ||
balance = await this.currency | ||
.balanceOf(accountAddress) | ||
.then(contract.converter); | ||
balance = new BigNumber(balance).shiftedBy(-this.data.currency.decimals); | ||
@@ -343,6 +355,5 @@ } else { | ||
approve(value) { | ||
return this.currency.approve( | ||
this.dat.address, | ||
value ? value : constants.MAX_UINT | ||
).then(contract.converter); | ||
return this.currency | ||
.approve(this.dat.address, value ? value : constants.MAX_UINT) | ||
.then(contract.converter); | ||
} | ||
@@ -353,25 +364,30 @@ /** | ||
approveFair(spender, value) { | ||
return this.dat.approve( | ||
spender, | ||
value ? value : constants.MAX_UINT | ||
).then(contract.converter).then(contract.converter); | ||
return this.dat | ||
.approve(spender, value ? value : constants.MAX_UINT) | ||
.then(contract.converter); | ||
} | ||
authorizedWalletToUserId(walletAddress) { | ||
return this.whitelist | ||
.authorizedWalletToUserId(walletAddress).then(contract.converter); | ||
.authorizedWalletToUserId(walletAddress) | ||
.then(contract.converter); | ||
} | ||
getAuthorizedUserIdInfo(userId) { | ||
return this.whitelist.getAuthorizedUserIdInfo(userId); | ||
return this.whitelist | ||
.getAuthorizedUserIdInfo(userId) | ||
.then(contract.converter); | ||
} | ||
approveNewUsers(accounts, jurisdictionIds) { | ||
return this.whitelist.approveNewUsers(accounts, jurisdictionIds); | ||
return this.whitelist | ||
.approveNewUsers(accounts, jurisdictionIds) | ||
.then(contract.converter); | ||
} | ||
addApprovedUserWallets(userIds, newWallets) { | ||
return this.whitelist.addApprovedUserWallets(userIds, newWallets); | ||
return this.whitelist | ||
.addApprovedUserWallets(userIds, newWallets) | ||
.then(contract.converter); | ||
} | ||
updateJurisdictionsForUserIds(userIds, jurisdictionIds) { | ||
return this.whitelist.updateJurisdictionsForUserIds( | ||
userIds, | ||
jurisdictionIds | ||
); | ||
return this.whitelist | ||
.updateJurisdictionsForUserIds(userIds, jurisdictionIds) | ||
.then(contract.converter); | ||
} | ||
@@ -382,9 +398,8 @@ setInvestorLimit(limit) { | ||
setInvestorLimitForJurisdiction(jurisdictionIds, limits) { | ||
return this.whitelist.setInvestorLimitForJurisdiction( | ||
jurisdictionIds, | ||
limits | ||
).then(contract.converter); | ||
return this.whitelist | ||
.setInvestorLimitForJurisdiction(jurisdictionIds, limits) | ||
.then(contract.converter); | ||
} | ||
halt(jurisdictionIds, dues) { | ||
return this.whitelist.halt(jurisdictionIds, dues); | ||
return this.whitelist.halt(jurisdictionIds, dues).then(contract.converter); | ||
} | ||
@@ -400,3 +415,4 @@ resume(jurisdictionIds) { | ||
const buyValue = await this.dat | ||
.estimateBuyValue(currencyValue.toFixed()); | ||
.estimateBuyValue(currencyValue.toFixed()) | ||
.then(contract.converter); | ||
return new BigNumber(buyValue).shiftedBy(-this.data.decimals); | ||
@@ -425,7 +441,5 @@ } | ||
return this.dat.buy( | ||
sendTo, | ||
currencyValue.toFixed(), | ||
minBuyValue.toFixed() | ||
).then(contract.converter); | ||
return this.dat | ||
.buy(sendTo, currencyValue.toFixed(), minBuyValue.toFixed()) | ||
.then(contract.converter); | ||
} | ||
@@ -438,3 +452,4 @@ async estimateSellValue(tokenAmount) { | ||
const sellValue = await this.dat | ||
.estimateSellValue(tokenValue.toFixed()); | ||
.estimateSellValue(tokenValue.toFixed()) | ||
.then(contract.converter); | ||
return new BigNumber(sellValue).shiftedBy(-this.data.currency.decimals); | ||
@@ -471,7 +486,5 @@ } catch (e) { | ||
} | ||
return this.dat.sell( | ||
sendTo, | ||
tokenValue.toFixed(), | ||
minSellValue.toFixed() | ||
).then(contract.converter); | ||
return this.dat | ||
.sell(sendTo, tokenValue.toFixed(), minSellValue.toFixed()) | ||
.then(contract.converter); | ||
} | ||
@@ -496,3 +509,3 @@ canSell() { | ||
.dp(0); | ||
return this.dat.burn(tokenValue.toFixed()); | ||
return this.dat.burn(tokenValue.toFixed()).then(contract.converter); | ||
} | ||
@@ -509,3 +522,3 @@ mint(sendToAddress, tokenAmount) { | ||
.dp(0); | ||
return this.dat.mint(sendTo, tokenValue.toFixed()); | ||
return this.dat.mint(sendTo, tokenValue.toFixed()).then(contract.converter); | ||
} | ||
@@ -516,3 +529,5 @@ manualBuy(sendToAddress, currencyAmount) { | ||
.dp(0); | ||
return this.dat.manualBuy(sendToAddress, buyAmount.toFixed()); | ||
return this.dat | ||
.manualBuy(sendToAddress, buyAmount.toFixed()) | ||
.then(contract.converter); | ||
} | ||
@@ -523,6 +538,8 @@ increaseCommitment(commitment, tokenAmount) { | ||
.dp(0); | ||
return this.dat.increaseCommitment( | ||
new BigNumber(commitment).shiftedBy(2).toFixed(), | ||
tokenValue.toFixed() | ||
); | ||
return this.dat | ||
.increaseCommitment( | ||
new BigNumber(commitment).shiftedBy(2).toFixed(), | ||
tokenValue.toFixed() | ||
) | ||
.then(contract.converter); | ||
} | ||
@@ -539,7 +556,9 @@ convertToCafe(commitment, tokenAmount, sendToAddress) { | ||
.dp(0); | ||
return this.dat.convertToCafe( | ||
new BigNumber(commitment).shiftedBy(2).toFixed(), | ||
tokenValue.toFixed(), | ||
sendTo | ||
); | ||
return this.dat | ||
.convertToCafe( | ||
new BigNumber(commitment).shiftedBy(2).toFixed(), | ||
tokenValue.toFixed(), | ||
sendTo | ||
) | ||
.then(contract.converter); | ||
} | ||
@@ -585,3 +604,5 @@ /** | ||
nonce === undefined | ||
? await this.dat.nonces(this.data.account.address).then(contract.converter) | ||
? await this.dat | ||
.nonces(this.data.account.address) | ||
.then(contract.converter) | ||
: nonce, | ||
@@ -599,3 +620,6 @@ deadline: deadline || constants.MAX_UINT, | ||
}; | ||
return this.provider.send("eth_signTypedData_v4", [this.data.account.address, JSON.stringify(data)]) | ||
return this.provider.send("eth_signTypedData_v4", [ | ||
this.data.account.address, | ||
JSON.stringify(data), | ||
]); | ||
} | ||
@@ -608,11 +632,13 @@ | ||
const v = parseInt(signatureHash.substring(128, 130), 16); | ||
return this.dat.permit( | ||
owner, | ||
spender, | ||
value === undefined ? constants.MAX_UINT : value, | ||
deadline || constants.MAX_UINT, | ||
v, | ||
r, | ||
s | ||
); | ||
return this.dat | ||
.permit( | ||
owner, | ||
spender, | ||
value === undefined ? constants.MAX_UINT : value, | ||
deadline || constants.MAX_UINT, | ||
v, | ||
r, | ||
s | ||
) | ||
.then(contract.converter); | ||
} | ||
@@ -647,20 +673,14 @@ | ||
} | ||
const result = await this.provider.send( | ||
"eth_call", | ||
[ | ||
{ | ||
to: this.currency.address, | ||
data: "0x54fd4d50", | ||
}, | ||
"latest", | ||
] | ||
); | ||
const result = await this.provider.send("eth_call", [ | ||
{ | ||
to: this.currency.address, | ||
data: "0x54fd4d50", | ||
}, | ||
"latest", | ||
]); | ||
const version = defaultAbiCoder.decode( | ||
"string", | ||
result | ||
); | ||
const version = defaultAbiCoder.decode("string", result); | ||
const domainData = { | ||
name: await this.currency.name(), | ||
name: await this.currency.name().then(contract.converter), | ||
version, | ||
@@ -676,3 +696,4 @@ chainId, | ||
nonce: await this.currency | ||
.nonces(this.data.account.address).then(contract.converter), | ||
.nonces(this.data.account.address) | ||
.then(contract.converter), | ||
}; | ||
@@ -688,4 +709,6 @@ const data = { | ||
}; | ||
return this.provider.send("eth_signTypedData_v4", [this.data.account.address, JSON.stringify(data)]) | ||
return this.provider.send("eth_signTypedData_v4", [ | ||
this.data.account.address, | ||
JSON.stringify(data), | ||
]); | ||
} | ||
@@ -698,11 +721,13 @@ | ||
const v = parseInt(signatureHash.substring(128, 130), 16); | ||
return this.currency.permit( | ||
owner, | ||
spender, | ||
value === undefined ? constants.MAX_UINT : value, | ||
deadline || constants.MAX_UINT, | ||
v, | ||
r, | ||
s | ||
); | ||
return this.currency | ||
.permit( | ||
owner, | ||
spender, | ||
value === undefined ? constants.MAX_UINT : value, | ||
deadline || constants.MAX_UINT, | ||
v, | ||
r, | ||
s | ||
) | ||
.then(contract.converter); | ||
} | ||
@@ -774,3 +799,5 @@ | ||
nonce === undefined | ||
? await this.dat.nonces(this.data.account.address).then(contract.converter) | ||
? await this.dat | ||
.nonces(this.data.account.address) | ||
.then(contract.converter) | ||
: nonce, | ||
@@ -788,3 +815,6 @@ deadline: deadline || constants.MAX_UINT, | ||
}; | ||
return this.provider.send("eth_signTypedData_v4", [this.data.account.address, JSON.stringify(data)]); | ||
return this.provider.send("eth_signTypedData_v4", [ | ||
this.data.account.address, | ||
JSON.stringify(data), | ||
]); | ||
} | ||
@@ -818,12 +848,14 @@ sendPermitBuy( | ||
const v = parseInt(signatureHash.substring(128, 130), 16); | ||
return this.dat.permitBuy( | ||
from, | ||
sendTo, | ||
currencyValue.toFixed(), | ||
minBuyValue.toFixed(), | ||
deadline || constants.MAX_UINT, | ||
v, | ||
r, | ||
s | ||
); | ||
return this.dat | ||
.permitBuy( | ||
from, | ||
sendTo, | ||
currencyValue.toFixed(), | ||
minBuyValue.toFixed(), | ||
deadline || constants.MAX_UINT, | ||
v, | ||
r, | ||
s | ||
) | ||
.then(contract.converter); | ||
} | ||
@@ -908,3 +940,6 @@ | ||
}; | ||
return this.provider.send("eth_signTypedData_v4", [this.data.account.address, JSON.stringify(data)]); | ||
return this.provider.send("eth_signTypedData_v4", [ | ||
this.data.account.address, | ||
JSON.stringify(data), | ||
]); | ||
} | ||
@@ -938,19 +973,23 @@ sendPermitSell( | ||
const v = parseInt(signatureHash.substring(128, 130), 16); | ||
return this.dat.permitSell( | ||
from, | ||
sendTo, | ||
fairValue.toFixed(), | ||
minCurrencyValue.toFixed(), | ||
deadline || constants.MAX_UINT, | ||
v, | ||
r, | ||
s | ||
); | ||
return this.dat | ||
.permitSell( | ||
from, | ||
sendTo, | ||
fairValue.toFixed(), | ||
minCurrencyValue.toFixed(), | ||
deadline || constants.MAX_UINT, | ||
v, | ||
r, | ||
s | ||
) | ||
.then(contract.converter); | ||
} | ||
configWhitelist(startDate, lockupGranularity) { | ||
return this.whitelist.configWhitelist(startDate, lockupGranularity); | ||
return this.whitelist | ||
.configWhitelist(startDate, lockupGranularity) | ||
.then(contract.converter); | ||
} | ||
transferWhitelistOwnership(newOwner) { | ||
return this.whitelist.transferOwnership(newOwner); | ||
return this.whitelist.transferOwnership(newOwner).then(contract.converter); | ||
} | ||
}; |
@@ -1,4 +0,17 @@ | ||
const BigNumber = require("bignumber.js"); | ||
const Ethers = require("ethers"); | ||
const converter = (value) => { | ||
if (value && value._isBigNumber) { | ||
return value.toString(); | ||
} | ||
if (typeof value === 'object') { | ||
const result = Array.isArray(value) ? [] : {} | ||
Object.keys(value).forEach(key => { | ||
result[key] = converter(value[key]) | ||
}) | ||
return result | ||
} | ||
return value | ||
} | ||
module.exports = { | ||
@@ -10,8 +23,3 @@ contract: { | ||
}, | ||
converter: async (value) => { | ||
if (value && value._isBigNumber) { | ||
return value.toString(); | ||
} | ||
return value | ||
} | ||
converter: converter | ||
}, | ||
@@ -18,0 +26,0 @@ constants: { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
104372
1766