-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add nars + ARS argentina peso support
- Loading branch information
Showing
5 changed files
with
115 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
const sdk = require("@defillama/sdk"); | ||
import { sumSingleBalance } from "../helper/generalUtil"; | ||
import { | ||
ChainBlocks, | ||
PeggedIssuanceAdapter, | ||
Balances, | ||
} from "../peggedAsset.type"; | ||
|
||
type ChainContracts = { | ||
[chain: string]: { | ||
issued: string; | ||
unreleased: string[]; | ||
}; | ||
}; | ||
|
||
const chainContracts: ChainContracts = { | ||
polygon: { | ||
issued: "0x65517425ac3ce259a34400bb67ceb39ff3ddc0bd", | ||
unreleased: [ | ||
"0x8388A0f91875e74Dc4705Abf2C9bBDD1bD40C585" | ||
], | ||
}, | ||
}; | ||
|
||
async function chainMinted(chain: string, decimals: number) { | ||
return async function ( | ||
_timestamp: number, | ||
_ethBlock: number, | ||
_chainBlocks: ChainBlocks | ||
) { | ||
let balances = {} as Balances; | ||
const totalSupply = ( | ||
await sdk.api.abi.call({ | ||
abi: "erc20:totalSupply", | ||
target: chainContracts[chain].issued, | ||
block: _chainBlocks?.[chain], | ||
chain: chain, | ||
}) | ||
).output; | ||
sumSingleBalance( | ||
balances, | ||
"peggedARS", | ||
totalSupply / 10 ** decimals, | ||
"issued", | ||
false | ||
); | ||
return balances; | ||
}; | ||
} | ||
|
||
async function chainUnreleased(chain: string, decimals: number) { | ||
return async function ( | ||
_timestamp: number, | ||
_ethBlock: number, | ||
_chainBlocks: ChainBlocks | ||
) { | ||
let balances = {} as Balances; | ||
for (let unreleased of chainContracts[chain].unreleased) { | ||
const unreleasedBalance = ( | ||
await sdk.api.abi.call({ | ||
abi: "erc20:balanceOf", | ||
target: chainContracts[chain].issued, | ||
params: [unreleased], | ||
block: _chainBlocks?.[chain], | ||
chain: chain, | ||
}) | ||
).output; | ||
sumSingleBalance( | ||
balances, | ||
"peggedARS", | ||
unreleasedBalance / 10 ** decimals, | ||
"unreleased", | ||
false | ||
); | ||
} | ||
return balances; | ||
}; | ||
} | ||
|
||
const adapter: PeggedIssuanceAdapter = { | ||
polygon: { | ||
minted: chainMinted("polygon", 18), | ||
unreleased: chainUnreleased("polygon", 18), | ||
}, | ||
}; | ||
|
||
export default adapter; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters