@rabbitholegg/questdk-plugin-fabric
Advanced tools
Comparing version 1.0.0-alpha.36 to 1.0.0-alpha.38
# @rabbitholegg/questdk-plugin-fabric | ||
## 1.0.0-alpha.38 | ||
### Patch Changes | ||
- [#505](https://github.com/rabbitholegg/questdk-plugins/pull/505) [`b38b9f49`](https://github.com/rabbitholegg/questdk-plugins/commit/b38b9f49616c18b48480e12d6d5a9570e95bc83b) Thanks [@mmackz](https://github.com/mmackz)! - update mint util functions | ||
## 1.0.0-alpha.37 | ||
### Minor Changes | ||
- [#473](https://github.com/rabbitholegg/questdk-plugins/pull/473) [`a373fdec`](https://github.com/rabbitholegg/questdk-plugins/commit/a373fdecb7e7f1ca91e79b95f8b40d82306bfe35) Thanks [@mmackz](https://github.com/mmackz)! - fix amount zero issue | ||
### Patch Changes | ||
- Updated dependencies [[`7284c9f7`](https://github.com/rabbitholegg/questdk-plugins/commit/7284c9f7aee7ed78463be945610a7d2cfb27d82d)]: | ||
- @rabbitholegg/questdk-plugin-utils@1.0.0-alpha.45 | ||
- @rabbitholegg/questdk@2.0.0-alpha.55 | ||
## 1.0.0-alpha.36 | ||
@@ -4,0 +22,0 @@ |
@@ -1,4 +0,4 @@ | ||
import { F as o } from "../index-B6CPAvs5.mjs"; | ||
import { F as o } from "../index-BblHPUiX.mjs"; | ||
export { | ||
o as Fabric | ||
}; |
@@ -1,2 +0,2 @@ | ||
export declare const FABRIC_ABI: { | ||
export declare const FABRIC_MINT_ABI: { | ||
inputs: { | ||
@@ -12,2 +12,13 @@ internalType: string; | ||
}[]; | ||
export declare const FABRIC_MINTFOR_ABI: { | ||
inputs: { | ||
internalType: string; | ||
name: string; | ||
type: string; | ||
}[]; | ||
name: string; | ||
outputs: never[]; | ||
stateMutability: string; | ||
type: string; | ||
}[]; | ||
export declare const SUBSCRIPTION_ABI: ({ | ||
@@ -14,0 +25,0 @@ inputs: never[]; |
import { type Address, type PublicClient } from 'viem'; | ||
interface ContractData { | ||
erc20Address: Address; | ||
minPurchaseSeconds: bigint; | ||
tps: bigint; | ||
client: PublicClient; | ||
minPurchaseSeconds: bigint | undefined; | ||
tps: bigint | undefined; | ||
} | ||
@@ -8,0 +7,0 @@ export declare function getContractData(chainId: number, contractAddress: Address, _client?: PublicClient): Promise<ContractData>; |
{ | ||
"name": "@rabbitholegg/questdk-plugin-fabric", | ||
"private": false, | ||
"version": "1.0.0-alpha.36", | ||
"version": "1.0.0-alpha.38", | ||
"exports": { | ||
@@ -19,3 +19,3 @@ "require": "./dist/cjs/index.js", | ||
"dependencies": { | ||
"@rabbitholegg/questdk-plugin-utils": "1.0.0-alpha.44", | ||
"@rabbitholegg/questdk-plugin-utils": "1.0.0-alpha.45", | ||
"@rabbitholegg/questdk": "2.0.0-alpha.55" | ||
@@ -22,0 +22,0 @@ }, |
@@ -1,2 +0,2 @@ | ||
export const FABRIC_ABI = [ | ||
export const FABRIC_MINT_ABI = [ | ||
{ | ||
@@ -18,13 +18,18 @@ inputs: [ | ||
{ | ||
internalType: 'address', | ||
name: 'account', | ||
type: 'address', | ||
internalType: 'uint256', | ||
name: 'numTokens', | ||
type: 'uint256', | ||
}, | ||
{ | ||
internalType: 'uint256', | ||
name: 'numTokens', | ||
name: 'referralCode', | ||
type: 'uint256', | ||
}, | ||
{ | ||
internalType: 'address', | ||
name: 'referrer', | ||
type: 'address', | ||
}, | ||
], | ||
name: 'mintFor', | ||
name: 'mintWithReferral', | ||
outputs: [], | ||
@@ -34,21 +39,19 @@ stateMutability: 'payable', | ||
}, | ||
] | ||
export const FABRIC_MINTFOR_ABI = [ | ||
{ | ||
inputs: [ | ||
{ | ||
internalType: 'uint256', | ||
name: 'numTokens', | ||
type: 'uint256', | ||
internalType: 'address', | ||
name: 'account', | ||
type: 'address', | ||
}, | ||
{ | ||
internalType: 'uint256', | ||
name: 'referralCode', | ||
name: 'numTokens', | ||
type: 'uint256', | ||
}, | ||
{ | ||
internalType: 'address', | ||
name: 'referrer', | ||
type: 'address', | ||
}, | ||
], | ||
name: 'mintWithReferral', | ||
name: 'mintFor', | ||
outputs: [], | ||
@@ -55,0 +58,0 @@ stateMutability: 'payable', |
@@ -7,3 +7,3 @@ import { getFees, getMintIntent, mint, simulateMint } from './Fabric' | ||
} from '@rabbitholegg/questdk-plugin-utils' | ||
import { apply } from '@rabbitholegg/questdk/filter' | ||
import { apply } from '@rabbitholegg/questdk' | ||
import { type Address } from 'viem' | ||
@@ -17,7 +17,7 @@ import { describe, expect, test } from 'vitest' | ||
const filter = await mint({ | ||
chainId: 1, | ||
contractAddress: '0xDeaDbeefdEAdbeefdEadbEEFdeadbeEFdEaDbeeF', | ||
chainId: 8453, | ||
contractAddress: '0x2efc6064239121d1d7efb503355daa82b87ee89c', | ||
}) | ||
expect(filter).toBeTypeOf('object') | ||
expect(Number(filter.chainId)).toBe(1) | ||
expect(Number(filter.chainId)).toBe(8453) | ||
if (typeof filter.to === 'string') { | ||
@@ -62,4 +62,9 @@ expect(filter.to).toMatch(/^0x[a-fA-F0-9]{40}$/) | ||
test(description, async () => { | ||
const filter = await mint(params) | ||
expect(apply(transaction, filter)).to.be.false | ||
try { | ||
const filter = await mint(params) | ||
const result = apply(transaction, filter) | ||
expect(result).toBe(false) | ||
} catch (error) { | ||
expect(error).toBeInstanceOf(Error) | ||
} | ||
}) | ||
@@ -66,0 +71,0 @@ }) |
@@ -1,2 +0,2 @@ | ||
import { FABRIC_ABI } from './abi' | ||
import { FABRIC_MINT_ABI, FABRIC_MINTFOR_ABI } from './abi' | ||
import { getContractData } from './utils' | ||
@@ -7,2 +7,3 @@ import { | ||
compressJson, | ||
GreaterThanOrEqual, | ||
} from '@rabbitholegg/questdk' | ||
@@ -12,2 +13,4 @@ import { | ||
DEFAULT_ACCOUNT, | ||
chainIdToViemChain, | ||
formatAmountToInteger, | ||
type MintIntentParams, | ||
@@ -20,3 +23,5 @@ } from '@rabbitholegg/questdk-plugin-utils' | ||
type TransactionRequest, | ||
createPublicClient, | ||
encodeFunctionData, | ||
http, | ||
zeroAddress, | ||
@@ -28,3 +33,15 @@ } from 'viem' | ||
): Promise<TransactionFilter> => { | ||
const { chainId, contractAddress, recipient } = mint | ||
const { chainId, contractAddress, amount, recipient } = mint | ||
const { minPurchaseSeconds, tps } = await getContractData( | ||
chainId, | ||
contractAddress, | ||
) | ||
if (minPurchaseSeconds == null || tps == null) { | ||
throw new Error('Contract data not found') | ||
} | ||
const numTokens = minPurchaseSeconds * tps * formatAmountToInteger(amount) | ||
return compressJson({ | ||
@@ -34,4 +51,13 @@ chainId, | ||
input: { | ||
$abi: FABRIC_ABI, | ||
account: recipient, | ||
$or: [ | ||
{ | ||
$abi: FABRIC_MINT_ABI, | ||
numTokens: GreaterThanOrEqual(numTokens), | ||
}, | ||
{ | ||
$abi: FABRIC_MINTFOR_ABI, | ||
numTokens: GreaterThanOrEqual(numTokens), | ||
account: recipient, | ||
}, | ||
], | ||
}, | ||
@@ -62,6 +88,10 @@ }) | ||
const mintUnits = typeof amount === 'number' ? BigInt(amount) : BigInt(1) | ||
if (!minPurchaseSeconds || !tps) { | ||
throw new Error('Contract data not found') | ||
} | ||
const mintCost = (minPurchaseSeconds as bigint) * (tps as bigint) * mintUnits | ||
const mintUnits = formatAmountToInteger(amount) | ||
const mintCost = minPurchaseSeconds * tps * mintUnits | ||
return { actionFee: mintCost, projectFee: BigInt(0) } | ||
@@ -84,6 +114,10 @@ } | ||
const mintArgs = [(minPurchaseSeconds as bigint) * (tps as bigint) * amount] | ||
if (!minPurchaseSeconds || !tps) { | ||
throw new Error('Contract data not found') | ||
} | ||
const mintArgs = [minPurchaseSeconds * tps * formatAmountToInteger(amount)] | ||
const data = encodeFunctionData({ | ||
abi: FABRIC_ABI, | ||
abi: FABRIC_MINT_ABI, | ||
functionName: 'mint', | ||
@@ -108,9 +142,15 @@ args: mintArgs, | ||
const _client = | ||
client ?? | ||
createPublicClient({ | ||
chain: chainIdToViemChain(chainId), | ||
transport: http(), | ||
}) | ||
const from = account ?? DEFAULT_ACCOUNT | ||
const { | ||
erc20Address, | ||
minPurchaseSeconds, | ||
tps, | ||
client: _client, | ||
} = await getContractData(chainId, contractAddress, client) | ||
const { erc20Address, minPurchaseSeconds, tps } = await getContractData( | ||
chainId, | ||
contractAddress, | ||
client, | ||
) | ||
@@ -122,8 +162,12 @@ // fail simulation if erc20 is used | ||
const mintArgs = [(minPurchaseSeconds as bigint) * (tps as bigint) * amount] | ||
if (!minPurchaseSeconds || !tps) { | ||
throw new Error('Contract data not found') | ||
} | ||
const mintArgs = [minPurchaseSeconds * tps * formatAmountToInteger(amount)] | ||
const result = await _client.simulateContract({ | ||
address: contractAddress, | ||
value, | ||
abi: FABRIC_ABI, | ||
abi: FABRIC_MINT_ABI, | ||
functionName: 'mint', | ||
@@ -130,0 +174,0 @@ args: mintArgs, |
@@ -7,5 +7,4 @@ import { SUBSCRIPTION_ABI } from './abi' | ||
erc20Address: Address | ||
minPurchaseSeconds: bigint | ||
tps: bigint | ||
client: PublicClient | ||
minPurchaseSeconds: bigint | undefined | ||
tps: bigint | undefined | ||
} | ||
@@ -42,6 +41,5 @@ | ||
erc20Address: erc20Address as Address, | ||
minPurchaseSeconds: minPurchaseSeconds as bigint, | ||
tps: tps as bigint, | ||
client: client as PublicClient, | ||
minPurchaseSeconds: minPurchaseSeconds as bigint | undefined, | ||
tps: tps as bigint | undefined, | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
919103
12677
9
+ Added@rabbitholegg/questdk-plugin-utils@1.0.0-alpha.45(transitive)
- Removed@rabbitholegg/questdk-plugin-utils@1.0.0-alpha.44(transitive)